//!!! Don't Create staics in Editor (Editor is recreated on every selection)
        //Have problems with static GenericMenu losing instances

        /// <summary>
        /// Raises the enable event on every selection of Blackboard GameObject and creates new instance of BlackboardEditor
        /// </summary>
        private void OnEnable()
        {
            //on every selection
            //Debug.Log ("OnEnable BlackBoard");

            variableListSerialized = serializedObject.FindProperty("variablesList");

            ((Blackboard)target).variablesList.ForEach(var => {
                if (var != null && var.serializedProperty == null)
                {
                    var.serializedProperty = EditorUtilityEx.SerializeObject(var);
                    EditorUtilityEx.UpdateSerializedProperty(var);
                }
            });


            __variablesReordableList = new ReorderableList(serializedObject, variableListSerialized,
                                                           true, true, true, true);
            __variablesReordableList.drawElementCallback = onDrawElement;

            __variablesReordableList.onAddDropdownCallback = onAddDropdownCallback;

            __variablesReordableList.drawHeaderCallback = onDrawHeaderElement;

            __variablesReordableList.onRemoveCallback = onRemoveCallback;

            __variablesReordableList.onSelectCallback = onSelectCallback;

            __variablesReordableList.elementHeight = 32f;


            _typesCustom = ((Blackboard)target).typesCustom as List <Type>;

            if (_typesCustom == null)
            {
                _typesCustom = new List <Type> ();
            }



            CreateGenericMenu();
        }
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);
        }