using UnityEngine; using UnityEditor; using System; using UnityEditor.SceneManagement; namespace UltraControls { [CustomEditor(typeof(UltraSetter))] [CanEditMultipleObjects] [Serializable] public class UltraSetterEditor : Editor { private UltraSetter m_master; public SerializedProperty m_property_is_started; public SerializedProperty m_property_name; public SerializedProperty m_property_identifierInFile; public SerializedProperty m_property_auto_load; void OnEnable() { if (m_master == null) { m_master = target as UltraSetter; } m_property_is_started = serializedObject.FindProperty("m_is_started"); m_property_name = serializedObject.FindProperty("m_name"); m_property_identifierInFile = serializedObject.FindProperty("m_identifierInFile"); m_property_auto_load = serializedObject.FindProperty("m_auto_load_after_finding_getter"); } void OnDisable() { } public override void OnInspectorGUI() { bool is_modified = m_master.UpdateIdentifierInFile(); if (is_modified) { EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene()); } serializedObject.Update(); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.TextArea(m_master.filepath_settings); EditorGUILayout.PropertyField(m_property_identifierInFile, new UnityEngine.GUIContent("IdentifierInFile")); EditorGUI.EndDisabledGroup(); EditorGUILayout.PropertyField(m_property_is_started, new UnityEngine.GUIContent("Start")); EditorGUI.BeginDisabledGroup(m_property_is_started.boolValue); { EditorGUILayout.PropertyField(m_property_name, new UnityEngine.GUIContent("Name")); EditorGUILayout.PropertyField(m_property_auto_load, new UnityEngine.GUIContent("Auto Load")); } EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); m_master.is_start = m_property_is_started.boolValue; if (!m_master.is_start) { m_master.ultracontros_name = m_property_name.stringValue; return; } EditorGUILayout.Separator(); if (!Application.isPlaying) { m_master.UpdateByUltraSetterEditor(); } Control[] controls = m_master.controls; if (controls == null) { return; } bool yes = EditorGUILayout.ToggleLeft("Save Settings", false); if (yes) { m_master.SaveSettings(); } yes = EditorGUILayout.ToggleLeft("Load Settings", false); if (yes) { m_master.LoadSettings(); } EditorGUILayout.Separator(); foreach (Control ctrl in controls) { switch(ctrl.ctrlType) { case CtrlType.Bool: ctrl.valBool = EditorGUILayout.Toggle(ctrl.name, ctrl.valBool); break; case CtrlType.Text: ctrl.text = EditorGUILayout.TextField(ctrl.name, ctrl.text); break; case CtrlType.Float: if (ctrl.hasRange) { ctrl.valFloat = EditorGUILayout.Slider(ctrl.name, ctrl.valFloat, ctrl.minFloat, ctrl.maxFloat); } else { ctrl.valFloat = EditorGUILayout.FloatField(ctrl.name, ctrl.valFloat); } break; case CtrlType.Int: if (ctrl.hasRange) { ctrl.valInt = (int)EditorGUILayout.Slider(ctrl.name, ctrl.valInt, ctrl.minInt, ctrl.maxInt); } else { ctrl.valInt = EditorGUILayout.IntField(ctrl.name, ctrl.valInt); } break; case CtrlType.Vec2F: ctrl.valVector2 = EditorGUILayout.Vector2Field(ctrl.name, ctrl.valVector2); break; case CtrlType.Vec3F: ctrl.valVector3 = EditorGUILayout.Vector3Field(ctrl.name, ctrl.valVector3); break; case CtrlType.Vec4F: ctrl.valVector4 = EditorGUILayout.Vector4Field(ctrl.name, ctrl.valVector4); break; case CtrlType.ColorF: ctrl.valColor = EditorGUILayout.ColorField(ctrl.name, ctrl.valColor); break; case CtrlType.Color: ctrl.valColor32 = EditorGUILayout.ColorField(ctrl.name, ctrl.valColor32); break; default: break; } } } } }//namespace UltraControls