Beispiel #1
0
        public override void OnInspectorGUI()
        {
            UndoManager.CheckUndo(owner, "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 = NewAsLocal();
                    }
                    else
                    {
                        newGraph = NewAsAsset();
                    }

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

                owner.graph = (Graph)EditorGUILayout.ObjectField(label, owner.graph, owner.graphType, false);
                return;
            }

            GUILayout.Space(10);

            //Graph comments ONLY if Bound graph
            if (owner.graphIsLocal)
            {
                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.graphIsLocal && 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 references through the Blackboard Variables\n\nBind Graph?", "YES", "NO"))
                    {
                        AssetToLocal();
                    }
                }

                //Reference graph
                if (!owner.graphIsLocal)
                {
                    owner.graph = (Graph)EditorGUILayout.ObjectField(label, owner.graph, owner.graphType, true);
                }
                else
                {
                    if (GUILayout.Button("Delete Bound Graph"))
                    {
                        if (EditorUtility.DisplayDialog("Delete Bound Graph", "Are you sure?", "YES", "NO"))
                        {
                            Undo.DestroyObjectImmediate(owner.graph);
                            Undo.RecordObject(owner, "Delete Bound");
                            owner.graph = 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 = GUI.skin.GetStyle("button").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 (GUI.changed)
            {
                EditorUtility.SetDirty(owner);
                if (owner.graph != null)
                {
                    EditorUtility.SetDirty(owner.graph);
                }
            }
        }
        ///<summary>Focus element. This also Pings it. User click.</summary>
        void FocusElement(HierarchyTree.Element e)
        {
            var element = e.GetFirstParentReferenceOfType <IGraphElement>();

            EditorApplication.delayCall += () => GraphEditor.FocusElement(element, true);
        }
Beispiel #3
0
        //...
        void DoValidGraphControls()
        {
            //Graph comments ONLY if Bound graph else readonly
            if (owner.graph != null)
            {
                if (owner.graphIsBound)
                {
                    GUI.contentColor     = Color.white.WithAlpha(0.6f);
                    owner.graph.comments = GUILayout.TextArea(owner.graph.comments, GUILayout.Height(45));
                    GUI.contentColor     = Color.white;
                    EditorUtils.CommentLastTextField(owner.graph.comments, "Graph comments...");
                }
                else
                {
                    GUI.enabled = false;
                    GUILayout.TextArea(owner.graph.comments, GUILayout.Height(45));
                    GUI.enabled = true;
                }
            }

            if (!isBoundGraphOnPrefabRoot)
            {
                //Open behaviour
                GUI.backgroundColor = Colors.lightBlue;
                if (GUILayout.Button(("Edit " + owner.graphType.Name.SplitCamelCase()).ToUpper()))
                {
                    GraphEditor.OpenWindow(owner);
                }
                GUI.backgroundColor = Color.white;
            }
            else
            {
                EditorGUILayout.HelpBox("Bound Graphs on prefabs can only be edited by opening the prefab in the prefab editor.", MessageType.Info);

                //Open prefab and behaviour
                GUI.backgroundColor = Colors.lightBlue;
                if (GUILayout.Button(("Open Prefab And Edit " + owner.graphType.Name.SplitCamelCase()).ToUpper()))
                {
                    AssetDatabase.OpenAsset(owner);
                    GraphEditor.OpenWindow(owner);
                }
                GUI.backgroundColor = Color.white;
            }

            //bind asset or delete bound graph
            if (!Application.isPlaying)
            {
                if (!owner.graphIsBound)
                {
                    if (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();
                        }
                    }
                }
                else
                {
                    if (GUILayout.Button("Delete Bound Graph"))
                    {
                        if (EditorUtility.DisplayDialog("Delete Bound Graph", "Are you sure?", "YES", "NO"))
                        {
                            Object.DestroyImmediate(owner.graph, true);
                            UndoUtility.RecordObject(owner, "Delete Bound Graph");
                            owner.SetBoundGraphReference(null);
                            UndoUtility.SetDirty(owner);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        //...
        void OnGUI()
        {
            EditorGUILayout.HelpBox("In PlayMode only, you can use this Utility, to search and find GraphOwners in the scene which are actively running.", MessageType.Info);

            search = EditorUtils.SearchField(search);
            EditorUtils.BoldSeparator();

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);

            var hasResult = false;

            foreach (var owner in activeOwners)
            {
                if (owner == null)
                {
                    continue;
                }
                hasResult = true;

                var displayName = string.Format("<size=9><b>{0}</b> ({1})</size>", owner.name, owner.graphType.FriendlyName());

                if (!string.IsNullOrEmpty(search))
                {
                    if (!StringUtils.SearchMatch(search, displayName))
                    {
                        continue;
                    }
                }

                GUILayout.BeginHorizontal(GUI.skin.box);
                GUILayout.Label(displayName);
                GUILayout.EndHorizontal();

                var elementRect = GUILayoutUtility.GetLastRect();
                EditorGUIUtility.AddCursorRect(elementRect, MouseCursor.Link);
                if (elementRect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.type == EventType.MouseMove)
                    {
                        willRepaint = true;
                    }
                    GUI.color = new Color(0.5f, 0.5f, 1, 0.3f);
                    GUI.DrawTexture(elementRect, EditorGUIUtility.whiteTexture);
                    GUI.color = Color.white;
                    if (Event.current.type == EventType.MouseDown)
                    {
                        Selection.activeObject = owner;
                        EditorGUIUtility.PingObject(owner);
                        if (Event.current.clickCount >= 2)
                        {
                            GraphEditor.OpenWindow(owner);
                        }
                        Event.current.Use();
                    }
                }
            }

            EditorGUILayout.EndScrollView();

            if (!hasResult)
            {
                ShowNotification(new GUIContent(Application.isPlaying ? "No GraphOwner is actively running." : "Application is not playing."));
            }

            if (Event.current.type == EventType.MouseLeaveWindow)
            {
                willRepaint = true;
            }
        }