Exemple #1
0
        void OnGUI()
        {
            if (__variable != null)
            {
                PropertyDrawer drawer;



                if (__variable.ValueType == typeof(UnityEvent))
                {
                    if (__variable.drawer == null)
                    {
                        __variable.drawer = new UnityEventDrawer();
                    }

                    drawer = __variable.drawer as PropertyDrawer;
                }
                else
                {
                    drawer = EditorUtilityEx.GetDrawer(__variable.ValueType);
                }


                Rect pos = new Rect(16, 16, Screen.width - 32, Screen.height - 32);

                if (drawer != null && __variable.serializedProperty != null)
                {
                    EditorGUI.BeginChangeCheck();
                    drawer.OnGUI(pos, __variable.serializedProperty as SerializedProperty, new GUIContent(__variable.name));

                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorUtilityEx.ApplySerializedPropertyChangeTo(__variable);
                    }
                }
            }
        }
Exemple #2
0
        public Rect DrawVariables(Rect position, SerializedProperty property)
        {
            UnityVariable currentVariable;



            currentVariable = (UnityVariable)property.objectReferenceValue;



            if (currentVariable != null)
            {
                Type type = currentVariable.ValueType;

                if (currentVariable.serializedProperty == null)
                {
                    currentVariable.Value = UnityVariable.Default(type);
                }


                //if UnityVariable isn't of type of known unityTypes or it is UnityEvent or have custom Drawer
                if (Array.IndexOf(EditorGUILayoutEx.unityTypes, type) < 0 ||
                    type == typeof(UnityEvent) || (currentVariable.drawer != null))
                {
                    //!!! this part is for Any UnityVariable with UnityTypes wiht UniUnityVariablePropertyDrawer (experimental)
                    if (currentVariable.ValueType != typeof(UnityEvent) && currentVariable.drawer != null)
                    {
                        variableNameTextFieldPos.y = position.y;
                        variableNameTextFieldPos.x = position.x;

                        EditorGUI.BeginChangeCheck();
                        currentVariable.name = EditorGUI.TextField(variableNameTextFieldPos, currentVariable.name);
                        if (EditorGUI.EndChangeCheck())
                        {
                            property.serializedObject.ApplyModifiedProperties();

                            //EditorUtility.SetDirty (currentVariable);
                        }

                        position.xMin = variableNameTextFieldPos.xMax + 10;


                        (currentVariable.drawer as PropertyDrawer).OnGUI(position, property, null);
                    }
                    else
                    {
                        currentVariable.name = EditorGUI.TextField(position, currentVariable.name);
                    }
                }
                else
                {
                    PropertyDrawer drawer;


                    drawer = EditorUtilityEx.GetDrawer(type);

                    if (drawer == null)
                    {
                        drawer = EditorUtilityEx.GetDefaultDrawer();
                    }


                    variableNameTextFieldPos.y = position.y;
                    variableNameTextFieldPos.x = position.x;

                    currentVariable.name = EditorGUI.TextField(variableNameTextFieldPos, currentVariable.name);
                    position.xMin        = variableNameTextFieldPos.xMax + 10;
                    //position.width =position.width- variableNameTextFieldPos.width;

                    EditorGUI.BeginChangeCheck();

                    if (currentVariable.serializedProperty == null)
                    {
                        currentVariable.serializedProperty = EditorUtilityEx.SerializeObject(currentVariable);
                    }

                    drawer.OnGUI(position, currentVariable.serializedProperty as SerializedProperty, new GUIContent(""));

                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorUtilityEx.ApplySerializedPropertyChangeTo(currentVariable);


                        EditorUtility.SetDirty(currentVariable);
                    }
                }
            }



            return(position);
        }