Beispiel #1
0
        public void DrawDefaultInspector()
        {
            // Get an iterator
            var iterator = m_SerializedNode.GetIterator();

            // Cache the indent level
            int indentLevel = EditorGUI.indentLevel;

            while (iterator.Next(iterator.current == null || (iterator.current.propertyType != NodePropertyType.Variable && !iterator.current.hideInInspector)))
            {
                SerializedNodeProperty current = iterator.current;
                if (!current.hideInInspector)
                {
                    EditorGUI.indentLevel = indentLevel + iterator.depth;
                    GUILayoutHelper.DrawNodeProperty(new GUIContent(current.label, current.tooltip), current, m_Target);
                }
            }

            // Restore the indent level
            EditorGUI.indentLevel = indentLevel;
        }
        /// <summary>
        /// The custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            var randomChild = target as RandomChild;

            if (randomChild != null)
            {
                // Get children nodes
                ActionNode[] children = randomChild.children;

                // Update serialized node data
                if (Event.current.type == EventType.Layout)
                {
                    this.serializedNode.Update();
                }

                // Get an iterator
                var iterator = serializedNode.GetIterator();

                // Cache the indent level
                int indentLevel = EditorGUI.indentLevel;

                if (iterator.Find("weight"))
                {
                    SerializedNodeProperty current = iterator.current;

                    // Cache the depth of array name
                    int depth = iterator.depth;

                    // Don't draw the size
                    iterator.Next(true);

                    // The current index of the child
                    int childIndex = 0;

                    // Draw children weight
                    while (iterator.Next(iterator.current == null || iterator.current.propertyType != NodePropertyType.Variable) && iterator.depth > depth)
                    {
                        current = iterator.current;
                        if (!current.hideInInspector)
                        {
                            EditorGUI.indentLevel = indentLevel + iterator.depth - 1;

                            // Its an array element of  weight array?
                            if (iterator.depth - depth == 1 && childIndex < children.Length)
                            {
                                GUILayoutHelper.DrawNodeProperty(new GUIContent(children[childIndex++].name + " Weight", current.tooltip), current, target);
                            }
                            else
                            {
                                GUILayoutHelper.DrawNodeProperty(new GUIContent(current.label, current.tooltip), current, target);
                            }
                        }
                    }
                }

                // Restore the indent level
                EditorGUI.indentLevel = indentLevel;

                // Apply modified properties
                this.serializedNode.ApplyModifiedProperties();
            }
        }
Beispiel #3
0
        /// <summary>
        /// The custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            // Update serialized node data
            if (Event.current.type == EventType.Layout)
            {
                this.serializedNode.Update();
            }

            // Cache the indent level
            int indentLevel = EditorGUI.indentLevel;

            // Get an iterator
            var iterator = this.serializedNode.GetIterator();

            // Draw the target object
            if (iterator.Find("targetObject"))
            {
                EditorGUI.indentLevel = indentLevel + iterator.depth;
                GUILayoutHelper.DrawNodeProperty(new GUIContent(iterator.current.label, iterator.current.tooltip), iterator.current, this.target);
            }

            // Draw the propertyName
            if (iterator.Find("propertyName"))
            {
                EditorGUI.indentLevel = indentLevel + iterator.depth;
                GUILayoutHelper.DrawNodeProperty(new GUIContent(iterator.current.label, iterator.current.tooltip), iterator.current, this.target);
            }

            // Draw the property value
            var propertyOrField = target as PropertyOrField;

            if (propertyOrField != null)
            {
                if (Event.current.type == EventType.Layout)
                {
                    propertyType = propertyOrField.propertyType;
                }

                if (propertyType != null)
                {
                    if (iterator.Find(propertyType.Name + "Value"))
                    {
                        EditorGUI.indentLevel = indentLevel + iterator.depth;
                        GUILayoutHelper.DrawNodeProperty(new GUIContent(propertyOrField.propertyName, iterator.current.tooltip), iterator.current, this.target);
                    }
                    else if (propertyType == typeof(GameObject) && iterator.Find("GameObjectValue"))
                    {
                        EditorGUI.indentLevel = indentLevel + iterator.depth;
                        GUILayoutHelper.DrawNodeProperty(new GUIContent(propertyOrField.propertyName, iterator.current.tooltip), iterator.current, this.target);
                    }
                    else if (typeof(UnityEngine.Object).IsAssignableFrom(propertyType) && iterator.Find("ObjectValue"))
                    {
                        EditorGUI.indentLevel = indentLevel + iterator.depth;
                        GUILayoutHelper.DrawNodeProperty(new GUIContent(propertyOrField.propertyName, iterator.current.tooltip), iterator.current, this.target);
                    }
                    else if (target is SetProperty && propertyType.IsEnum && iterator.Find("StringValue.value"))
                    {
                        string value = (string)iterator.current.value;

                        // The enum is defined?
                        if (!System.Enum.IsDefined(propertyType, value))
                        {
                            iterator.current.value = value = "0";
                        }

                        // Used to check if the gui was changed in editor
                        EditorGUI.BeginChangeCheck();
                        // Draw an enum popup field
                        System.Enum newValue = EditorGUILayout.EnumPopup(new GUIContent(propertyOrField.propertyName, iterator.current.tooltip), (System.Enum)System.Enum.Parse(propertyType, value));
                        // Value changed?
                        if (EditorGUI.EndChangeCheck())
                        {
                            iterator.current.value = newValue.ToString();
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField(propertyType.Name, "not supported.");
                    }
                }
            }

            // Restore the indent level
            EditorGUI.indentLevel = indentLevel;

            // Apply modified properties
            this.serializedNode.ApplyModifiedProperties();
        }