コード例 #1
0
ファイル: NodeEditor.cs プロジェクト: pandey623/UNETGame
        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;
        }
コード例 #2
0
        /// <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();
            }
        }
コード例 #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();
        }
コード例 #4
0
        /// <summary>
        /// Draws a node property in the GUI.
        /// <param name="guiContent">The content of the property.</param>
        /// <param name="property">The property do be drawn.</param>
        /// <param name="node">The node that owns the property.</param>
        /// <param name="objectType">An optionaly type to be used to with UnityEngine.Object properties.</param>
        /// <param name="useCustomDrawer">If false the custom node drawer will be ignored if it exists.</param>
        /// </summary>
        public static void DrawNodeProperty(GUIContent guiContent, SerializedNodeProperty property, ActionNode node, Type objectType = null, bool useCustomDrawer = true)
        {
            if (s_Styles == null)
            {
                s_Styles = new GUILayoutHelper.Styles();
            }

            // Get the current value
            object value = property.value;
            // Create the newValue
            object newValue = value;

            // Variable?
            if (property.propertyType == NodePropertyType.Variable)
            {
                GUILayoutHelper.VariableField(guiContent, property, node);
            }
            // Use custom property drawer?
            else if (useCustomDrawer && property.customDrawer != null)
            {
                property.customDrawer.OnGUI(property, node, guiContent);
                return;
            }
            else
            {
                EditorGUI.BeginChangeCheck();

                switch (property.propertyType)
                {
                // Integer
                case NodePropertyType.Integer:
                    newValue = EditorGUILayout.IntField(guiContent, value != null ? (int)value : 0);
                    break;

                // Float
                case NodePropertyType.Float:
                    newValue = EditorGUILayout.FloatField(guiContent, (float)value);
                    break;

                // Boolean
                case NodePropertyType.Boolean:
                    newValue = EditorGUILayout.Toggle(guiContent, (bool)value);
                    break;

                // String
                case NodePropertyType.String:
                    newValue = EditorGUILayout.TextField(guiContent, (string)value);
                    break;

                // Color
                case NodePropertyType.Color:
                    newValue = EditorGUILayout.ColorField(guiContent, (Color)value);
                    break;

                // Vector2
                case NodePropertyType.Vector2:
                        #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                    newValue = EditorGUILayout.Vector2Field(guiContent.text, (Vector2)value);
                        #else
                    newValue = EditorGUILayout.Vector2Field(guiContent, (Vector2)value);
                        #endif
                    break;

                // Vector3
                case NodePropertyType.Vector3:
                        #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                    newValue = EditorGUILayout.Vector3Field(guiContent.text, (Vector3)value);
                        #else
                    newValue = EditorGUILayout.Vector3Field(guiContent, (Vector3)value);
                        #endif
                    break;

                // Quaternion
                case NodePropertyType.Quaternion:
                        #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                    newValue = Quaternion.Euler(EditorGUILayout.Vector3Field(guiContent.text, ((Quaternion)value).eulerAngles));
                        #else
                    newValue = Quaternion.Euler(EditorGUILayout.Vector3Field(guiContent, ((Quaternion)value).eulerAngles));
                        #endif
                    break;

                // Vector4
                case NodePropertyType.Vector4:
                    newValue = EditorGUILayout.Vector4Field(guiContent.text, (Vector4)value);
                    break;

                // Rect
                case NodePropertyType.Rect:
                    newValue = EditorGUILayout.RectField(guiContent, (Rect)value);
                    break;

                // Enum
                case NodePropertyType.Enum:
                    newValue = EditorGUILayout.EnumPopup(guiContent, (System.Enum)value);
                    break;

                // AnimationCurve
                case NodePropertyType.AnimationCurve:
                    newValue = EditorGUILayout.CurveField(guiContent, (AnimationCurve)value);
                    break;

                // UnityObject
                case NodePropertyType.UnityObject:
                    newValue = EditorGUILayout.ObjectField(guiContent, value as UnityEngine.Object, objectType != null ? objectType : property.type, !AssetDatabase.Contains(node.self));
                    break;

                // Array
                case NodePropertyType.Array:
                    EditorGUILayout.LabelField(guiContent);
                    GUI.changed = false;
                    break;

                // ArraySize
                case NodePropertyType.ArraySize:
                    goto case NodePropertyType.Integer;

                // LayerMask
                case NodePropertyType.LayerMask:
                    newValue = GUILayoutHelper.LayerMaskField(guiContent, (LayerMask)value);
                    break;

                // Not Supported
                default:
                    Color oldGuiColor = GUI.color;
                    GUI.color = Color.red;
                    EditorGUILayout.LabelField(guiContent.text, "Not supported.");
                    GUI.color = oldGuiColor;
                    break;
                }

                // Value changed?
                if (EditorGUI.EndChangeCheck())
                {
                    property.value = newValue;
                    Event.current.Use();
                }
            }
        }