コード例 #1
0
        void DisplayDebugMenu(Rect pos)
        {
            var node = mContextNode == null ? null : mContextNode.GetRuntimeNode();

            if (node == null)
            {
                return;
            }
            BehaviourTreeRunner.AssetBinder subtree = null;
            if (node != null && node.Asset != null && TargetRunner != null)
            {
                subtree = TargetRunner.GetBinder((x) => x.Name == node.Asset.GetInstanceID().ToString("x"));
            }
            if (subtree != null && subtree.RuntimeTree != null)
            {
                sDebugMenu.AddItem("打开子行为树", (menu, index, data) =>
                {
                    mAssetBinder.SetBehaviourBinder(data as BehaviourTreeRunner.AssetBinder);
                    mContextNode = null;
                }, subtree);
            }
            else
            {
                sDebugMenu.RemoveItem("打开子行为树");
            }
            sDebugMenu.Display(this, pos);
        }
コード例 #2
0
        public static void InitModules()
        {
            sHotkeyMenu    = new BTHotkeyMenu();
            sNewTreeMenu   = new BTEditorMenu();
            sTreeMenu      = new BTEditorMenu();
            sContextMenu   = new BTEditorMenu();
            sNodeMenu      = new BTEditorMenu();
            sConditionMenu = new BTEditorMenu();
            sDebugMenu     = new BTEditorMenu();

            var newtree = BTEditorMenu.NewItem("创建行为树", (menu, index, data) =>
            {
                var tree  = ScriptableObject.CreateInstance <BehaviourTreeAsset>();
                tree.name = "INNER_AI";
                menu.editor.Binder.SetBehaviourTreeAsset(tree);
            });

            var resetItem = BTEditorMenu.NewItem("重置", (menu, index, data) =>
            {
                menu.editor.Binder.Reset();
            });

            var saveitem = BTEditorMenu.NewItem("保存", (menu, index, data) => {
                menu.editor.Binder.SaveAsset();
            });

            var delitem = BTEditorMenu.NewItem("删除", (menu, index, data) => {
                menu.editor.DeleteContext(menu.editor.mContextNode);
            });

            var moveup = BTEditorMenu.NewItem("向上移动", (menu, index, data) =>
            {
                menu.editor.MoveContextCondition(-1);
            });
            var movedown = BTEditorMenu.NewItem("向下移动", (menu, index, data) =>
            {
                menu.editor.MoveContextCondition(1);
            });
            var copy = BTEditorMenu.NewItem("复制", (menu, index, data) =>
            {
                menu.editor.CopySelection();
            });
            var paste = BTEditorMenu.NewItem("粘贴", (menu, index, data) => {
                menu.editor.PasteSelection();
            });

            sNewTreeMenu.AddItem(newtree);
            sTreeMenu.AddItem(newtree);
            sTreeMenu.AddItem(resetItem);
            sContextMenu.AddItem(resetItem);
            sDebugMenu.AddItem(resetItem);
            sTreeMenu.AddItem(saveitem);
            sContextMenu.AddItem(saveitem);
            sContextMenu.AddItem(copy);
            sTreeMenu.AddItem(paste);
            sContextMenu.AddItem(delitem);
            sConditionMenu.AddItem(delitem);
            sConditionMenu.AddItem(moveup);
            sConditionMenu.AddItem(movedown);

            BTEditorMenu.OnItemSelected newnode = (menu, index, data) =>
            {
                var mod = data as AIModules.Module;
                if (mod != null)
                {
                    menu.editor.AddNewNode(mod);
                }
            };

            var composites = AIModules.GetModules(AIModules.CATE_COMPOSITE);
            var tasks      = AIModules.GetModules(AIModules.CATE_TASK);

            foreach (var t in composites)
            {
                var item = BTEditorMenu.NewItem(t.Path, newnode, t);
                sTreeMenu.AddItem(item);
                //sContextMenu.AddItem(item);
                sNodeMenu.AddItem(item);
            }
            foreach (var t in tasks)
            {
                var item = BTEditorMenu.NewItem(t.Path, newnode, t);
                sTreeMenu.AddItem(item);
                //sContextMenu.AddItem(item);
                sNodeMenu.AddItem(item);
            }
            var conds = AIModules.GetModules(AIModules.CATE_CONDITION);

            foreach (var t in conds)
            {
                var item = BTEditorMenu.NewItem(t.Path, newnode, t);
                sContextMenu.AddItem(item);
                sConditionMenu.AddItem(item);
            }
            var servs = AIModules.GetModules(AIModules.CATE_SERVICE);

            foreach (var t in servs)
            {
                var item = BTEditorMenu.NewItem(t.Path, newnode, t);
                sTreeMenu.AddItem(item);
                //sContextMenu.AddItem(item);
                sNodeMenu.AddItem(item);
            }

            sDebugMenu.AddItem("添加断点", (menu, index, data) =>
            {
                var item = menu.editor.mContextNode;
                if (item != null)
                {
                    item.BreakToggle = true;
                }
            }, null);
            sDebugMenu.AddItem("删除断点", (menu, index, data) =>
            {
                var item = menu.editor.mContextNode;
                if (item != null)
                {
                    item.BreakToggle = false;
                }
            }, null);
        }