Example #1
0
        public static GenericMenu CreateBehaviourTreeEditorMenu(BehaviourTreeEditor editor)
        {
            GenericMenu        menu       = new GenericMenu();
            BTEditorTreeLayout treeLayout = BTEditorStyle.TreeLayout;

            menu.AddItem(new GUIContent("New"), false, editor.CreateNewBehaviourTree);
            menu.AddItem(new GUIContent("Open"), false, editor.OpenBehaviourTree);
            if (BTEditorCanvas.Current.ReadOnly)
            {
                menu.AddDisabledItem(new GUIContent("Save"));
            }
            else
            {
                menu.AddItem(new GUIContent("Save"), false, editor.SaveBehaviourTree);
                AssetDatabase.SaveAssets();
            }

            var recentFiles = editor.NavigationHistory.RecentFiles;

            if (recentFiles.Count > 0)
            {
                GenericMenu.MenuFunction2 func = (obj) =>
                {
                    BTAsset asset = AssetDatabase.LoadAssetAtPath <BTAsset>((string)obj);
                    BehaviourTreeEditor.Open(asset);
                };

                foreach (var file in recentFiles)
                {
                    menu.AddItem(new GUIContent("Recent Files/" + file.Replace('/', '\\')), false, func, file);
                }
            }
            else
            {
                menu.AddItem(new GUIContent("Recent Files/Empty"), false, () => { });
            }

            menu.AddSeparator("");

            menu.AddItem(new GUIContent("Snap To Grid"), BTEditorCanvas.Current.SnapToGrid, () =>
            {
                BTEditorCanvas.Current.SnapToGrid = !BTEditorCanvas.Current.SnapToGrid;
            });

            foreach (BTEditorTreeLayout layout in Enum.GetValues(typeof(BTEditorTreeLayout)))
            {
                menu.AddItem(new GUIContent("Layout/" + layout.ToString()), treeLayout == layout, (obj) =>
                {
                    BTEditorStyle.TreeLayout = (BTEditorTreeLayout)obj;
                }, layout);
            }

            CreateHelpOptions(menu);

            return(menu);
        }
Example #2
0
        public Vector2 GetSize(string content, BTEditorTreeLayout layout)
        {
            if (!string.IsNullOrEmpty(content))
            {
                if (layout == BTEditorTreeLayout.Horizontal)
                {
                    return(GetSizeHorizontal(content));
                }
                else
                {
                    return(GetSizeVertical(content));
                }
            }

            return(new Vector2(180, 40));
        }
        private void DrawTransitions()
        {
            Vector2            nodeSize   = BTEditorStyle.GetNodeSize(m_node);
            Rect               position   = new Rect(NodePosition + BTEditorCanvas.Current.Position, nodeSize);
            BTEditorTreeLayout treeLayout = BTEditorStyle.TreeLayout;

            foreach (var child in m_children)
            {
                Vector2       childNodeSize = BTEditorStyle.GetNodeSize(child.Node);
                Rect          childPosition = new Rect(child.Node.Position + BTEditorCanvas.Current.Position, childNodeSize);
                RunningStatus childStatus   = BTEditorCanvas.Current.IsDebuging ? GetNodeStatus(child.Node) : RunningStatus.None;
                Color         color         = BTEditorStyle.GetTransitionColor(childStatus);
                Vector2       nodeCenter    = position.center;
                Vector2       childCenter   = childPosition.center;

                if (treeLayout == BTEditorTreeLayout.Vertical)
                {
                    if (Mathf.Approximately(nodeCenter.y, childCenter.y) || Mathf.Approximately(nodeCenter.x, childCenter.x))
                    {
                        BTEditorUtils.DrawLine(nodeCenter, childCenter, color);
                    }
                    else
                    {
                        BTEditorUtils.DrawLine(nodeCenter, nodeCenter + Vector2.up * (childCenter.y - nodeCenter.y) / 2, color);

                        BTEditorUtils.DrawLine(nodeCenter + Vector2.up * (childCenter.y - nodeCenter.y) / 2,
                                               childCenter + Vector2.up * (nodeCenter.y - childCenter.y) / 2, color);

                        BTEditorUtils.DrawLine(childCenter, childCenter + Vector2.up * (nodeCenter.y - childCenter.y) / 2, color);
                    }
                }
                else if (treeLayout == BTEditorTreeLayout.Horizontal)
                {
                    //BTEditorUtils.DrawBezier(nodeCenter, childCenter, color);
                    Vector2 nodeRight = new Vector2(position.center.x + nodeSize.x / 2, position.center.y);
                    Vector2 childLeft = new Vector2(childPosition.center.x - childNodeSize.x / 2, childPosition.center.y);
                    BTEditorUtils.DrawBezier(nodeRight, childLeft, color);
                }
                else
                {
                    BTEditorUtils.DrawLine(nodeCenter, childCenter, color);
                }
            }
        }