Example #1
0
 public static void UpdateProject()
 {
     ProjectVersionUpdater.DoVersionUpdate();
 }
        public override void OnInspectorGUI()
        {
            if (!owner.hasUpdated2_6_2)
            {
                EditorGUILayout.HelpBox("IMPORTANT: Due to a core version update change, this Graph Owner created with a previous version, is temporary locked.\nPlease update your project to the new version simply by clicking the button bellow.", MessageType.Warning);
                if (GUILayout.Button("Update Project", GUILayout.Height(40)))
                {
                    ProjectVersionUpdater.DoVersionUpdate();
                }
                return;
            }

            UndoManager.CheckUndo(owner, "Graph Owner Inspector");
            if (owner.graph != null && owner.graphIsBound)
            {
                UndoManager.CheckUndo(owner.graph, "Graph Owner Inspector");
            }

            var ownerPeristant = EditorUtility.IsPersistent(owner);
            var label          = owner.graphType.Name.SplitCamelCase();

            if (owner.graph == null)
            {
                EditorGUILayout.HelpBox(owner.GetType().Name + " needs a " + label + ".\nAssign or Create a new one...", MessageType.Info);
                if (!Application.isPlaying && GUILayout.Button("CREATE NEW"))
                {
                    Graph newGraph = null;
                    if (EditorUtility.DisplayDialog("Create Graph", "Create a Bound or an Asset Graph?\n\n" +
                                                    "Bound Graph is saved with the GraphOwner and you can use direct scene references within it.\n\n" +
                                                    "Asset Graph is an asset file and can be reused amongst any number of GraphOwners.\n\n" +
                                                    "You can convert from one type to the other at any time.",
                                                    "Bound", "Asset"))
                    {
                        newGraph = NewAsBound();
                    }
                    else
                    {
                        newGraph = NewAsAsset();
                    }

                    if (newGraph != null)
                    {
                        GraphEditor.OpenWindow(owner);
                    }
                }

                owner.graph = (Graph)EditorGUILayout.ObjectField(label, owner.graph, owner.graphType, false);
                if (GUI.changed)
                {
                    owner.Validate();
                    EditorUtility.SetDirty(owner);
                }
                return;
            }

            GUILayout.Space(10);


            //Graph comments ONLY if Bound graph
            if (owner.graphIsBound)
            {
                owner.graph.graphComments = GUILayout.TextArea(owner.graph.graphComments, GUILayout.Height(45));
                EditorUtils.TextFieldComment(owner.graph.graphComments, "Graph comments...");
            }

            //Open behaviour
            GUI.backgroundColor = EditorUtils.lightBlue;
            if (GUILayout.Button(("Edit " + owner.graphType.Name.SplitCamelCase()).ToUpper()))
            {
                GraphEditor.OpenWindow(owner);
            }
            GUI.backgroundColor = Color.white;

            if (!Application.isPlaying)
            {
                if (!owner.graphIsBound && GUILayout.Button("Bind Graph"))
                {
                    if (EditorUtility.DisplayDialog("Bind Graph", "This will make a local copy of the graph, bound to the owner.\n\nThis allows you to make local changes and assign scene object references directly.\n\nNote that you can also use scene object references through the use of Blackboard Variables.\n\nBind Graph?", "YES", "NO"))
                    {
                        AssetToBound();
                    }
                }

                //Reference graph
                if (!owner.graphIsBound)
                {
                    owner.graph = (Graph)EditorGUILayout.ObjectField(label, owner.graph, owner.graphType, true);
                }
                else
                {
                    if (GUILayout.Button("Delete Bound Graph"))
                    {
                        var safe = !EditorUtility.IsPersistent(owner.graph) || AssetDatabase.IsSubAsset(owner.graph);
                        if (safe && EditorUtility.DisplayDialog("Delete Bound Graph", "Are you sure?", "YES", "NO"))
                        {
                            Undo.DestroyObjectImmediate(owner.graph);
                            Undo.RecordObject(owner, "Delete Bound Graph");
                            owner.SetBoundGraphReference(null);
                            EditorUtility.SetDirty(owner);
                        }
                    }
                }
            }



            //basic options
//			owner.blackboard = (Blackboard)EditorGUILayout.ObjectField("Blackboard", owner.blackboard as Blackboard, typeof(Blackboard), true);
            owner.enableAction  = (GraphOwner.EnableAction)EditorGUILayout.EnumPopup("On Enable", owner.enableAction);
            owner.disableAction = (GraphOwner.DisableAction)EditorGUILayout.EnumPopup("On Disable", owner.disableAction);


            EditorUtils.Separator();

            //derived GUI
            OnExtraOptions();

            //execution debug controls
            if (Application.isPlaying && owner.graph != null && !ownerPeristant)
            {
                var pressed = new GUIStyle(GUI.skin.GetStyle("button"));
                pressed.normal.background = pressed.active.background;

                GUILayout.BeginHorizontal("box");
                GUILayout.FlexibleSpace();

                if (GUILayout.Button(EditorUtils.playIcon, owner.isRunning || owner.isPaused? pressed : (GUIStyle)"button"))
                {
                    if (owner.isRunning || owner.isPaused)
                    {
                        owner.StopBehaviour();
                    }
                    else
                    {
                        owner.StartBehaviour();
                    }
                }

                if (GUILayout.Button(EditorUtils.pauseIcon, owner.isPaused? pressed : (GUIStyle)"button"))
                {
                    if (owner.isPaused)
                    {
                        owner.StartBehaviour();
                    }
                    else
                    {
                        owner.PauseBehaviour();
                    }
                }

                OnGrapOwnerControls();
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            EditorUtils.ShowAutoEditorGUI(owner);
            EditorUtils.EndOfInspector();

            UndoManager.CheckDirty(owner);
            if (owner.graph != null && owner.graphIsBound)
            {
                UndoManager.CheckDirty(owner.graph);
            }
        }