예제 #1
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();
                }
            }
        }
예제 #2
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();
                }
            }
        }