예제 #1
0
        void ShowBasicGUI()
        {
            GUILayout.Space(10);
            graph.name          = EditorGUILayout.TextField("Name", graph.name);
            graph.graphComments = GUILayout.TextArea(graph.graphComments, GUILayout.Height(45));
            EditorUtils.TextFieldComment(graph.graphComments);

            GUI.backgroundColor = new Color(0.8f, 0.8f, 1);
            if (GUILayout.Button(string.Format("EDIT {0}", graph.GetType().Name.SplitCamelCase().ToUpper())))
            {
                GraphEditor.OpenWindow(graph);
            }
            GUI.backgroundColor = Color.white;
        }
        //name, description, edit button
        public void ShowBasicGUI()
        {
            GUILayout.Space(10);
            graph.category = GUILayout.TextField(graph.category);
            EditorUtils.TextFieldComment(graph.category, "Category...");

            graph.comments = GUILayout.TextArea(graph.comments, GUILayout.Height(45));
            EditorUtils.TextFieldComment(graph.comments, "Comments...");

            GUI.backgroundColor = Colors.lightBlue;
            if (GUILayout.Button(string.Format("EDIT {0}", graph.GetType().Name.SplitCamelCase().ToUpper())))
            {
                GraphEditor.OpenWindow(graph);
            }
            GUI.backgroundColor = Color.white;
        }
예제 #3
0
        //...
        static void ProccessMessage(Logger.Message msg)
        {
            var graph = Graph.GetElementGraph(msg.context);

            if (graph == null)
            {
                return;
            }

            var unityContext = graph.agent != null? (Object)graph.agent.gameObject : (Object)graph;

            Selection.activeObject = unityContext;
            EditorGUIUtility.PingObject(unityContext);

            var editor = GraphEditor.current;

            if (editor == null || GraphEditor.currentGraph != graph)
            {
                editor = GraphEditor.OpenWindow(graph);
            }

            IGraphElement element = null;

            if (msg.context is IGraphElement)
            {
                element = (IGraphElement)msg.context;
            }
            if (msg.context is Task)
            {
                element = graph.GetTaskParentElement((Task)msg.context);
            }
            if (msg.context is BBParameter)
            {
                element = graph.GetParameterParentElement((BBParameter)msg.context);
            }

            EditorApplication.delayCall += () => GraphEditor.FocusElement(element, true);
        }
        public override void OnInspectorGUI()
        {
            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.comments = GUILayout.TextArea(owner.graph.comments, GUILayout.Height(45));
                EditorUtils.TextFieldComment(owner.graph.comments, "Graph comments...");
            }

            //Open behaviour
            GUI.backgroundColor = Colors.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"))
                    {
                        if (EditorUtility.DisplayDialog("Delete Bound Graph", "Are you sure?", "YES", "NO"))
                        {
                            Object.DestroyImmediate(owner.graph, true);
                            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(Icons.playIcon, owner.isRunning || owner.isPaused? pressed : (GUIStyle)"button"))
                {
                    if (owner.isRunning || owner.isPaused)
                    {
                        owner.StopBehaviour();
                    }
                    else
                    {
                        owner.StartBehaviour();
                    }
                }

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

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

            EditorUtils.ReflectedObjectInspector(owner);
            EditorUtils.EndOfInspector();

            UndoManager.CheckDirty(owner);
            if (owner.graph != null && owner.graphIsBound)
            {
                UndoManager.CheckDirty(owner.graph);
            }
        }
        //...
        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);
                        }
                    }
                }
            }
        }
예제 #6
0
 public static void OpenEditor()
 {
     GraphEditor.OpenWindow();
 }
        //...
        void OnGUI()
        {
            if (EditorGUIUtility.isProSkin)
            {
                GUI.Box(new Rect(0, 0, Screen.width, Screen.height), string.Empty, Styles.shadowedBackground);
            }

            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("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;
            }
        }
예제 #8
0
        public override void OnInspectorGUI()
        {
            UndoManager.CheckUndo(this, "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 + ". Assign or Create a new one", MessageType.Info);
                if (!Application.isPlaying && GUILayout.Button("CREATE NEW"))
                {
                    Graph newGraph = null;
                    if (EditorUtility.DisplayDialog("Create Graph", "Create a Local or an Asset Graph?\n\n" +
                                                    "Local Graph is binded to and saved with the Scene 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",
                                                    "Local", "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
            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"))
            {
                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 binded to the scene.\n This allows you to make changes and assing scene object references directly\nNote that you can also do so through the Blackboard", "YES", "NO"))
                    {
                        AssetToLocal();
                    }
                }

                if (owner.graphIsLocal && GUILayout.Button("Save Graph Asset"))
                {
                    if (EditorUtility.DisplayDialog("Save Graph Asset", "This will save the local graph to an Asset graph file so that it can be reused by other GraphOwners as well\nProceed?", "YES", "NO"))
                    {
                        LocalToAsset();
                    }
                }
            }


            if (!Application.isPlaying)
            {
                //Reference graph
                if (!owner.graphIsLocal)
                {
                    GUI.color   = new Color(1, 1, 1, 0.5f);
                    owner.graph = (Graph)EditorGUILayout.ObjectField(label, owner.graph, owner.graphType, true);
                    GUI.color   = Color.white;
                }
                else
                {
                    if (GUILayout.Button("Delete Local Graph"))
                    {
                        if (EditorUtility.DisplayDialog("Delete Local Graph", "Are you sure?", "YES", "NO"))
                        {
                            Undo.DestroyObjectImmediate(owner.graph);
                            Undo.RecordObject(owner, "Delete Local");
                            owner.graph = null;
                            EditorUtility.SetDirty(owner);
                        }
                    }
                }
            }
            else
            {
                //EditorGUILayout.LabelField("Graph", "Non inspectable at runtime");
            }

            owner.blackboard = (Blackboard)EditorGUILayout.ObjectField("Blackboard", (Blackboard)owner.blackboard, typeof(Blackboard), true);

            //basic options
            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, EditorUtility.IsPersistent(owner));
            EditorUtils.EndOfInspector();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(owner);
                if (owner.graph != null)                 //this is only done for the comments :/
                {
                    EditorUtility.SetDirty(owner.graph);
                }
            }
        }