示例#1
0
        protected override void CanvasContextMenu()
        {
            if (_currentEvent.type != EventType.MouseDown || _currentEvent.button != 1 || _currentEvent.clickCount != 1 || BehaviorTreeEditor.active == null)
            {
                return;
            }

            GenericMenu canvasMenu = new GenericMenu();

            // Composite
            canvasMenu.AddItem(new GUIContent("Create Composite/Selector"), false, delegate()
            {
                BehaviorTreeEditorUtility.AddNode <Selector>(_mousePosition, BehaviorTreeEditor.active);
            });
            canvasMenu.AddItem(new GUIContent("Create Composite/Sequence"), false, delegate()
            {
                BehaviorTreeEditorUtility.AddNode <Sequence>(_mousePosition, BehaviorTreeEditor.active);
            });
            // Task
            canvasMenu.AddItem(new GUIContent("Create Task/Wait"), false, delegate()
            {
                BehaviorTreeEditorUtility.AddNode <Wait>(_mousePosition, BehaviorTreeEditor.active);
            });
            canvasMenu.AddSeparator("Create Task/");
            canvasMenu.AddItem(new GUIContent("Create Task/Task"), false, delegate()
            {
                BehaviorTreeEditorUtility.AddNode <Task>(_mousePosition, BehaviorTreeEditor.active);
            });

            canvasMenu.ShowAsContext();
        }
示例#2
0
        private void SelectBehaviorBrain()
        {
            GUIContent content = new GUIContent(BehaviorTreeEditor.active != null ? BehaviorTreeEditor.active.name : "[None Selected]");
            float      width   = EditorStyles.toolbarDropDown.CalcSize(content).x;

            width = Mathf.Clamp(width, 100f, width);
            if (GUILayout.Button(content, EditorStyles.toolbarDropDown, GUILayout.Width(width)))
            {
                GenericMenu menu = new GenericMenu();
                if (BehaviorTreeEditor.active != null)
                {
                    SelectBehaviorBrainMenu(BehaviorTreeEditor.active, ref menu);
                }

                menu.AddItem(new GUIContent("[Craete New]"), false, delegate()
                {
                    BehaviorTree bt = AssetCreator.CreateAsset <BehaviorTree>(true);
                    if (bt != null)
                    {
                        bt.Name = bt.name;

                        Root root   = BehaviorTreeEditorUtility.AddNode <Root>(BehaviorTreeEditor.center, bt);
                        bt.rootNode = root;
                        root.Name   = "Root";

                        AssetDatabase.SaveAssets();
                        BehaviorTreeEditor.SelectBehaviorTrees(bt);
                    }
                });
                menu.ShowAsContext();
            }
        }
示例#3
0
        public static void CreateBehaviorTrees()
        {
            // This code is borrowed from ICode(https://www.assetstore.unity3d.com/en/#!/content/13761)
            BehaviorTree bt = AssetCreator.CreateAsset <BehaviorTree>(false);

            if (bt != null)
            {
                bt.Name = bt.name;
                Root root = BehaviorTreeEditorUtility.AddNode <Root>(BehaviorTreeEditor.center, bt);
                bt.rootNode = root;
                root.Name   = "Root";
                AssetDatabase.SaveAssets();
            }
        }
示例#4
0
        public static T AddNode <T>(Vector2 position, BehaviorTree bt)
        {
            if (bt == null)
            {
                Debug.LogWarning("Can't add a node to the behavior trees, because the behavior trees are null.");
                return(default(T));
            }

            Node node = ScriptableObject.CreateInstance(typeof(T)) as Node;

            node.hideFlags = HideFlags.HideInHierarchy;

            node.Name     = BehaviorTreeEditorUtility.GenerateName <T>();
            node.comment  = node.Name;
            node.bt       = bt;
            bt.nodes      = ArrayUtility.Add <Node>(bt.nodes, node);
            node.position = new Rect(position.x, position.y, BehaviorTreeEditorStyles.NodeNormalWidth, BehaviorTreeEditorStyles.NodeNormalHeight);

            if (EditorUtility.IsPersistent(bt))
            {
                AssetDatabase.AddObjectToAsset(node, bt);
            }

            if (node is BehaviorTree)
            {
                node.position.width  = 150f;
                node.position.height = 45f;

                Root root = BehaviorTreeEditorUtility.AddNode <Root>(BehaviorTreeEditor.center, node as BehaviorTree);
                root.Name = "Root";
            }
            else if (node is Wait)
            {
                Wait wait = node as Wait;
                wait.tick    = 0.1f;
                wait.comment = "Wait: 0.1s";
            }

            AssetDatabase.SaveAssets();
            return((T)(object)node);
        }