コード例 #1
0
        /// <summary>
        /// Draws the component inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            EditorGUI.BeginChangeCheck();

            var callback = GetDrawCallback();

            if (callback != null)
            {
                // Wait to draw the inherited component until the Script field has been drawn. This will allow the state foldout to be drawn after the inherited component.
                callback();
            }
            else
            {
                // If a callback doesn't exist use the InspectorFoldout attribute to draw all of the fields without having to create custom inspectors for each class.
                for (int i = 0; i < m_FoldoutFields.Count; ++i)
                {
                    if (m_FoldoutFields[i].Count > 0)
                    {
                        if (!string.IsNullOrEmpty(m_FoldoutNames[i]))
                        {
                            // Draw the fields indented under a foldout.
                            if (Foldout(m_FoldoutNames[i]))
                            {
                                EditorGUI.indentLevel++;
                                for (int j = 0; j < m_FoldoutFields[i].Count; ++j)
                                {
                                    EditorGUILayout.PropertyField(PropertyFromName(m_FoldoutFields[i][j].Name), true);
                                }
                                EditorGUI.indentLevel--;
                            }
                        }
                        else
                        {
                            // There is no foldout so don't indent the EditorGUI.
                            for (int j = 0; j < m_FoldoutFields[i].Count; ++j)
                            {
                                EditorGUILayout.PropertyField(PropertyFromName(m_FoldoutFields[i][j].Name), true);
                            }
                        }
                    }
                }
            }

            if (Foldout("States"))
            {
                m_ReorderableStateList = StateInspector.DrawStates(m_ReorderableStateList, serializedObject, PropertyFromName("m_States"),
                                                                   SelectedIndexKey, OnStateListDraw, OnStateListAdd, OnStateListReorder, OnStateListRemove);
                // EditorGUILayout.PropertyField(PropertyFromName("m_States"), true);
            }

            if (EditorGUI.EndChangeCheck())
            {
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                serializedObject.ApplyModifiedProperties();
                StateInspector.UpdateDefaultStateValues((target as StateBehavior).States);
            }
        }
コード例 #2
0
        /// <summary>
        /// Draws all of the added states.
        /// </summary>
        private void OnStateListDraw(Rect rect, int index, bool isActive, bool isFocused)
        {
            EditorGUI.BeginChangeCheck();

            StateInspector.OnStateListDraw(target, (target as StateBehavior).States, PropertyFromName("m_States"), rect, index);

            if (EditorGUI.EndChangeCheck())
            {
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                serializedObject.ApplyModifiedProperties();
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates a new preset and adds it to a new state in the list.
        /// </summary>
        private void CreatePreset()
        {
            EditorGUI.BeginChangeCheck();

            var stateComponent = target as StateBehavior;

            stateComponent.States = StateInspector.CreatePreset(target, stateComponent.States, m_ReorderableStateList, SelectedIndexKey);
            if (EditorGUI.EndChangeCheck())
            {
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                serializedObject.ApplyModifiedProperties();
            }
        }
コード例 #4
0
        /// <summary>
        /// The ReordableList remove button has been pressed. Remove the selected state.
        /// </summary>
        private void OnStateListRemove(ReorderableList list)
        {
            EditorGUI.BeginChangeCheck();

            var stateComponent = target as StateBehavior;

            stateComponent.States = StateInspector.OnStateListRemove(stateComponent.States, PropertyFromName("m_States"), SelectedIndexKey, list);

            if (EditorGUI.EndChangeCheck())
            {
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                serializedObject.ApplyModifiedProperties();
            }
        }
コード例 #5
0
        /// <summary>
        /// The list has been reordered. Ensure the reorder is valid.
        /// </summary>
        private void OnStateListReorder(ReorderableList list)
        {
            EditorGUI.BeginChangeCheck();

            var stateComponent = target as StateBehavior;

            stateComponent.States = StateInspector.OnStateListReorder(stateComponent.States);

            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetInt(SelectedIndexKey, list.index);
                InspectorUtility.RecordUndoDirtyObject(target, "Change Value");
                serializedObject.ApplyModifiedProperties();
            }
        }
コード例 #6
0
 /// <summary>
 /// Adds a new state element to the list.
 /// </summary>
 private void OnStateListAdd(ReorderableList list)
 {
     StateInspector.OnStateListAdd(AddExistingPreset, CreatePreset);
 }