コード例 #1
0
ファイル: BTGraph.cs プロジェクト: pedro15/MoonBehavior
        /// <summary>
        /// BT Canvas extra GUI States
        /// </summary>
        /// <param name="controller">MoonEditor Controller</param>
        /// <returns>Defined gui states</returns>
        public override Dictionary <int, System.Action> CanvasGUIStates(MoonEditorController controller)
        {
            Dictionary <int, System.Action> dic = new Dictionary <int, System.Action>();

            dic.Add(4, () =>
            {
                MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);
                NewScriptName = MoonModal.InputPanel(new Vector2(200, 100), "Create " + ((NewScriptMode == 0) ? " Action" : "Decision"), "Ok", "Cancel", "Class Name", NewScriptName,
                                                     () =>
                {
                    if (MoonIO.ValidFileName(NewScriptName))
                    {
                        if (MoonIO.ValidClassName(NewScriptName))
                        {
                            string Savefolder = MoonSettings.ActionsSaveDirectory + "/BehaviorTrees";

                            if (NewScriptMode >= 1)
                            {
                                // create Decition
                                Savefolder += "/_Decisions";
                            }
                            CreateBTScript(Savefolder, NewScriptMode == 0, NewScriptName);
                            NewScriptName = string.Empty;
                            controller.CurrentGUIState = 0;
                        }
                    }
                }, () =>
                {
                    NewScriptName = string.Empty;
                    controller.CurrentGUIState = 0;
                });
            });

            return(dic);
        }
コード例 #2
0
ファイル: BTGraph.cs プロジェクト: pedro15/MoonBehavior
 /// <summary>
 /// Canvas extra elements
 /// </summary>
 public override void OnCanvasGUI()
 {
     if (!RootNode)
     {
         GUI.DrawTexture(new Rect(10, Screen.height - 80, 30, 30), EditorGUIUtility.FindTexture("console.erroricon"));
         MoonGUI.DrawCanvasLabel(new Rect(40, Screen.height - 80, Screen.width - 40, 30),
                                 new GUIContent("No root node asigned !"), Color.white, 20, false);
     }
 }
コード例 #3
0
        /// <summary>
        /// Draws and enables the node editor
        /// </summary>
        /// <param name="e">User event</param>
        public void DoNodeEditor(Event e)
        {
            Rect _zoomrect = new Rect(new Vector2(0, 19), Window.position.size);

            Vector2 pivotscale = _zoomrect.size / 2;

            Graph.ZoomPivot = GUIScaleUtility.BeginScale(ref _zoomrect, pivotscale, Graph.Zoom, true, false);

            // Node drawing

            UnityEngine.Profiling.Profiler.BeginSample("MoonBehavior: Node Drawing");

            if (Graph.Nodes.Count > 0 && (e.type == EventType.Layout || e.type == EventType.Repaint))
            {
                DrawNodes(Graph.Nodes, _zoomrect);
            }

            UnityEngine.Profiling.Profiler.EndSample();

            // Node interaction

            UnityEngine.Profiling.Profiler.BeginSample("MoonBehavior: Node events");

            HandleNodeEvents(e, Graph);

            UnityEngine.Profiling.Profiler.EndSample();

            if (ActiveOutput != null)
            {
                MoonGUI.DrawLine(ActiveOutput.GetPosition(), e.mousePosition, new Color(1, 1, 1, 0.6f));
            }

            GUIScaleUtility.EndScale();

            HandleAddNodes(e);
            HandleContext();
        }
コード例 #4
0
ファイル: BTNodeOutput.cs プロジェクト: pedro15/MoonBehavior
 /// <summary>
 /// Custom Line drawing
 /// </summary>
 /// <param name="Start">Start point</param>
 /// <param name="End">End point</param>
 /// <param name="Target">Target point</param>
 public override void DrawLine(Vector2 Start, Vector2 End, NodeInput Target)
 {
     MoonGUI.DrawLine(Start, End, Color.white, new GUIContent(Target.Order.ToString(), "Order"), true);
 }
コード例 #5
0
ファイル: NodeOutput.cs プロジェクト: pedro15/MoonBehavior
 /// <summary>
 /// Draws a line for an Node input
 /// </summary>
 /// <param name="Start">Start position</param>
 /// <param name="End">End position</param>
 /// <param name="Target">Input target</param>
 public virtual void DrawLine(Vector2 Start, Vector2 End, NodeInput Target)
 {
     MoonGUI.DrawLine(Start, End, Color.white, true);
 }
コード例 #6
0
        /// <summary>
        /// Displays the editor depending on it's state
        /// </summary>
        /// <param name="e">User event</param>
        public void DoEditor(Event e)
        {
            GUIState st = (GUIState)CurrentGUIState;

            switch (st)
            {
            case GUIState.Normal:

                if (WorkingGraph != null)
                {
                    MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), WorkingGraph.Offset, WorkingGraph.Zoom);

                    canvas.DoNodeEditor(e);
                    WorkingGraph.OnCanvasGUI();
                }
                else
                {
                    MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);
                    MoonGUI.DrawCanvasLabel(new Rect(10, 15, 500, 300), new GUIContent("No Graph"), 26, true);
                }

                break;

            case GUIState.New:

                MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);

                if (ModuleData != null)
                {
                    NewGraphName = MoonModal.InputPanel(new Vector2(200, 100), "New " + ModuleData.Name, "Ok", "Cancel", "Name",
                                                        NewGraphName,
                                                        () =>
                    {
                        if (MoonIO.ValidFileName(NewGraphName))
                        {
                            string foldername = (!string.IsNullOrEmpty(ModuleData.ExportFolderName)) ?
                                                ModuleData.ExportFolderName : ModuleData.Name;

                            NodeGraph newg = MoonIO.CreateGraphAsset(NewGraphName, foldername, ModuleData.GraphType,
                                                                     ModuleData.ModuleType);
                            if (newg != null)
                            {
                                WorkingGraph = newg;
                            }
                            NewGraphName    = string.Empty;
                            CurrentGUIState = (int)GUIState.Normal;
                        }
                    },
                                                        () =>
                    {
                        NewGraphName    = string.Empty;
                        CurrentGUIState = (int)GUIState.Normal;
                    });
                }
                else
                {
                    CurrentGUIState = (int)GUIState.Normal;
                }

                break;

            case GUIState.Open:

                MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);

                MoonModal.OpenGraphPanel(ref OpenGraphOffset, ref OpenGraphSearch, FoundGraphs, (NodeGraph ng) =>
                {
                    WorkingGraph    = ng;
                    CurrentGUIState = (int)GUIState.Normal;
                }, () => CurrentGUIState = (int)GUIState.Normal, () => FoundGraphs = MoonIO.GetAllGraphs());

                if (!string.Equals(OpenGraphSearch, LastOpenGraphSearch))
                {
                    FoundGraphs         = MoonIO.GetAllGraphs(OpenGraphSearch);
                    LastOpenGraphSearch = OpenGraphSearch;
                }

                break;

            case GUIState.SaveAs:

                MoonGUI.DrawGrid(new Rect(0, 17, Screen.width, Screen.height), Vector2.zero);

                NewGraphName = MoonModal.InputPanel(new Vector2(200, 100), "Save as ", "Ok", "Cancel", "Name",
                                                    NewGraphName,
                                                    () =>
                {
                    if (MoonIO.ValidFileName(NewGraphName))
                    {
                        NodeGraph copy = MoonIO.CopyGraph(WorkingGraph, NewGraphName);

                        if (copy != null)
                        {
                            WorkingGraph = copy;
                        }

                        CurrentGUIState = (int)GUIState.Normal;
                    }
                },
                                                    () => CurrentGUIState = (int)GUIState.Normal);

                break;

            default:

                for (int i = 0; i < UserKeyStates.Length; i++)
                {
                    if (CurrentGUIState == UserKeyStates[i])
                    {
                        System.Action act;
                        if (UserStates.TryGetValue(UserKeyStates[i], out act))
                        {
                            act.Invoke();
                        }
                    }
                }

                break;
            }
        }
コード例 #7
0
        /// <summary>
        /// Displays open graph panel
        /// </summary>
        /// <param name="scrollpoint">Open graph scroll point</param>
        /// <param name="searchfilter">Open graph search filter</param>
        /// <param name="Graphs">Graphs list</param>
        /// <param name="OnOpen">On open action</param>
        /// <param name="OnCancel">On cancel action</param>
        /// <param name="OnDelete">On delete action</param>
        public static void OpenGraphPanel(ref Vector2 scrollpoint, ref string searchfilter, NodeGraph[] Graphs,
                                          System.Action <NodeGraph> OnOpen, System.Action OnCancel, System.Action OnDelete)
        {
            Vector2 size = new Vector2(350, 320);

            Rect r = new Rect((Screen.width / 2) - (size.x / 2), (Screen.height / 2) - (size.y / 2), size.x, size.y);

            GUI.Box(r, "", GUI.skin.FindStyle("WindowBackground"));


            GUI.BeginGroup(r);

            GUI.Box(new Rect(0, 0, r.width - 50, 15), "", EditorStyles.toolbar);

            GUI.Label(new Rect(5, 0, 100, 20), "Open Graph");

            if (GUI.Button(new Rect(r.width - 50, 0, 50, 15), "Close", EditorStyles.toolbarButton))
            {
                OnCancel.Invoke();
            }

            Rect searchRect = new Rect(10, 28, r.width - 20, 15);

            searchfilter = MoonGUI.SearchTextField(searchRect, searchfilter);

            //EditorGUI.DrawRect(searchRect, Color.blue);

            Rect ScrollRect = new Rect(5, 50, r.width - 15, r.height - 60);

            GUI.Box(ScrollRect, "", GUI.skin.FindStyle("AnimationKeyframeBackground"));

            scrollpoint = GUI.BeginScrollView(ScrollRect, scrollpoint, new Rect(0, 0, ScrollRect.width - 20, Graphs.Length * 25), false, true);

            if (Graphs != null && Graphs.Length > 0)
            {
                for (int i = 0; i < Graphs.Length; i++)
                {
                    Rect baserect = new Rect(ScrollRect.x, i * 25, ScrollRect.width - 25, 20);

                    NodeGraph current = Graphs[i];

                    if (current != null)
                    {
                        GraphModuleAttribute module = MoonReflection.GetAttribute(current.GetType(), typeof(GraphModuleAttribute), true)
                                                      as GraphModuleAttribute;

                        if (module != null)
                        {
                            GUI.Box(baserect, "");

                            GUI.BeginGroup(baserect);

                            Rect labelrect = new Rect(5, 0, baserect.width * 0.8f, baserect.height);


                            Rect namerect = new Rect(labelrect.x, labelrect.y, labelrect.width * 0.55f, labelrect.height);

                            //EditorGUI.DrawRect(namerect, Color.blue);


                            GUI.Label(namerect, current.name);

                            Rect TypeRect = new Rect(namerect.xMax + 5, labelrect.y, labelrect.width * 0.45f, labelrect.height);

                            GUI.Label(TypeRect, module.Name, GUI.skin.FindStyle("PreToolbar"));

                            //EditorGUI.DrawRect(TypeRect, Color.red);

                            Rect loadrect = new Rect(TypeRect.xMax + 5, TypeRect.y + 2, 15, 15);

                            if (GUI.Button(loadrect, new GUIContent("", "Load"), GUI.skin.FindStyle("OL Plus")))
                            {
                                OnOpen.Invoke(current);
                            }

                            Rect removerect = new Rect(loadrect.xMax + 5, loadrect.y, 15, 15);

                            if (GUI.Button(removerect, new GUIContent("", "Remove"), GUI.skin.FindStyle("OL Minus")))
                            {
                                bool ok = EditorUtility.DisplayDialog("Delete", "Are you sure to DELETE the graph '" + current.name + "' ?",
                                                                      "Yes", "No");

                                if (ok)
                                {
                                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(current));
                                    OnDelete.Invoke();
                                }
                            }

                            GUI.EndGroup();
                        }
                    }
                    else
                    {
                        OnDelete.Invoke();
                    }
                }
            }
            GUI.EndScrollView();

            GUI.EndGroup();
        }
コード例 #8
0
        /// <summary>
        /// Displays the add node window panel
        /// </summary>
        /// <param name="Position">Panel position</param>
        /// <param name="searchfilter">Panel search filter string</param>
        /// <param name="NodeScroll">Panel scroll position</param>
        /// <param name="Collections">Node collections to fill panel</param>
        /// <param name="PanelRect">Out panel area rect</param>
        /// <param name="OnAddNode">On add node event</param>
        public static void AddNodePanel(NodeGraph WorkingGraph, Vector2 Position, ref string searchfilter, ref Vector2 NodeScroll, Nodes.NodeCollection[] Collections, out Rect PanelRect,
                                        System.Action <System.Type> OnAddNode)
        {
            Rect r = new Rect(new Vector2(Mathf.Clamp(Position.x, 0, Screen.width - 290),
                                          Mathf.Clamp(Position.y, 0, Screen.height - 350)), new Vector2(280, 300));

            GUI.Box(r, "", GUI.skin.FindStyle("WindowBackground"));

            GUI.BeginGroup(r);
            int totalNodes = Collections.Select((NodeCollection n) => n.Nodes.Length).Sum();

            GUI.Label(new Rect(5, 3, r.width - 10, 15), "Add node (" + totalNodes + ")");

            searchfilter = MoonGUI.SearchTextField(new Rect(5, 20, r.width - 10, 15), searchfilter);

            Rect scroll_rect = new Rect(10, 45, r.width - 20, r.height - 55);

            GUI.Box(scroll_rect, "", GUI.skin.FindStyle("AnimationKeyframeBackground"));


            NodeScroll = GUI.BeginScrollView(scroll_rect, NodeScroll, new Rect(0, 0, scroll_rect.width - 15,
                                                                               NodeCollection.GetCollectionsHeight(Collections)), false, true);

            for (int i = 0; i < Collections.Length; i++)
            {
                NodeCollection curr = Collections[i];

                float Y_Pos = ((i - 1) >= 0) ? Collections[i - 1].MaxY : i * NodeCollection.NodeHeight;

                Rect coll_rect = new Rect(8, Y_Pos, scroll_rect.width - 30, curr.GetHeight());
                curr.MaxY = coll_rect.y + coll_rect.height;

                GUI.Box(coll_rect, "");

                GUI.BeginGroup(coll_rect);

                GUIStyle   collLabelSkin         = GUI.skin.FindStyle("AssetLabel");
                GUIContent label_collection      = new GUIContent(curr.CategoryName + " (" + curr.Nodes.Length + ")");
                float      label_collectionWidth = coll_rect.width * 0.8f;

                GUI.Label(new Rect(25, 5, label_collectionWidth, 15), label_collection, collLabelSkin);

                if (GUI.Button(new Rect(5, 5, 15, 15), "", GUI.skin.FindStyle
                                   ((curr.FoldOut ? "OL Minus" : "OL Plus"))))
                {
                    curr.FoldOut = !curr.FoldOut;
                }

                if (curr.FoldOut)
                {
                    for (int j = 0; j < curr.Nodes.Length; j++)
                    {
                        NodeItem item = curr.Nodes[j];

                        Rect itemrect = new Rect(0, 25 + (j * NodeCollection.NodeHeight), coll_rect.width, NodeCollection.NodeHeight);


                        bool inItem = itemrect.Contains(Event.current.mousePosition);

                        if (inItem)
                        {
                            EditorGUI.DrawRect(itemrect, new Color32(0, 112, 197, 255));

                            if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                            {
                                OnAddNode(item.NodeType);
                            }
                        }

                        GUIStyleState _labelcolored = inItem ? new GUIStyleState()
                        {
                            textColor = Color.white
                        }
                            : EditorStyles.label.normal;

                        GUI.BeginGroup(itemrect);

                        Rect ItemIconRect = new Rect(5, 2.5f, 16, 16);

                        if (item.Icon != null)
                        {
                            GUI.DrawTexture(ItemIconRect, item.Icon);
                        }
                        else
                        {
                        }

                        Rect ItemLabelRect = new Rect(25, 4, itemrect.width - 25, itemrect.height);

                        GUI.Label(ItemLabelRect, item.Name, new GUIStyle(EditorStyles.label)
                        {
                            normal    = _labelcolored,
                            alignment = TextAnchor.UpperLeft
                        });

                        GUI.EndGroup();
                    }
                }

                GUI.EndGroup();
            }

            GUI.EndScrollView();

            GUI.EndGroup();

            PanelRect = r;
        }