Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void DeleteContext(BehaviourNode node)
        {
            if (node == null)
            {
                return;
            }
            var t = node.GetContext();

            if (t != null)
            {
                mAssetBinder.targetTree.EditorDeleteNode(t);
                if (t.Asset is BTNodeAsset)
                {
                    AddDelayTask(ACT_UPDATE_WIRES, mWires.UpdateWires);
                }
                if (node != RootNode && node.GetNode() == null)
                {
                    AIGraph.RemoveElement(node);
                }
                else
                {
                    node.Resize();
                }
            }
        }
Exemplo n.º 3
0
        void AddLink(BehaviourNode from, BehaviourNode to)
        {
            LinkPath p = new LinkPath();

            p.from = from;
            p.to   = to;
            links.Add(p);
        }
        public override void ModifyParentAs(BehaviourNode node)
        {
            base.ModifyParentAs(node);
            var todo = BTEditableDO.New <BTModifyParent>(editor);

            todo.isParentRoot = node == editor.RootNode;
            todo.child        = mNode;
            todo.parent       = node == null ? null : node.GetNode();
            editor.DoEdit(todo);
        }
 public override bool EnableParentAs(BehaviourNode node)
 {
     if (base.EnableParentAs(node))
     {
         if (node == null || node == editor.RootNode)
         {
             return(true);
         }
         var p = node.GetNode();
         return(p != null && !p.IsChildOf(mNode));
     }
     return(false);
 }
Exemplo n.º 6
0
        void UpdateTreeGraph()
        {
            mCopyDo = null;
            AddHistory(mAssetBinder.source);
            mBindStack.Clear();
            mUndoStack.Clear();
            AIGraph.ClearElements();
            mContextNode = null;
            RaycastNode  = null;
            RequestChild(null);

            if (Application.isPlaying)
            {
                var bind = mAssetBinder.RuntimeBinder;
                while (bind != null)
                {
                    mBindStack.Insert(0, bind);
                    bind = bind.Parent;
                }
            }
            AIGraph.AddElement(RootNode);
            if (mAssetBinder.targetTree != null)
            {
                List <BTNode> datas = new List <BTNode>();
                mAssetBinder.targetTree.GetAllNodes(datas);
                foreach (var t in datas)
                {
                    if (t.Asset == null)
                    {
                        mAssetBinder.targetTree.EditorDeleteNode(t);
                        continue;
                    }
                    if (t.Asset is BTNodeAsset)
                    {
                        var node = new BTNodeGUI(this, t);
                        AIGraph.AddElement(node);
                    }
                }
            }
            RootNode.Resize();
            mWires.UpdateWires();
            var runner = TargetRunner;

            BlackboardMonitor.Visible    = runner != null && Application.isPlaying;
            BlackboardMonitor.Blackboard = runner == null ? null : runner.Blackboard;
        }
Exemplo n.º 7
0
 bool InteractCraphClick(EMouseButton btn, Vector2 mousePos)
 {
     if (btn == EMouseButton.left)
     {
         if (IsRequestParentOrChild && mAssetBinder.targetTree != null)
         {
             mContextNode = RaycastNode;
             mContextPos  = AIGraph.CalculateLocalPosition(mousePos);
             sNodeMenu.Display(this, new Rect(Event.current.mousePosition, Vector2.zero));
         }
         else
         {
             ClearSelection();
         }
         return(true);
     }
     else if (btn == EMouseButton.right)
     {
         if (RaycastNode != null && !mSelection.Contains(RaycastNode))
         {
             ClearSelection();
         }
         mContextNode = RaycastNode;
         mContextPos  = AIGraph.CalculateLocalPosition(mousePos);
         if (Application.isPlaying)
         {
             DisplayDebugMenu(new Rect(Event.current.mousePosition, Vector2.zero));
             //EditorUtility.DisplayCustomMenu(new Rect(mousePos, Vector2.zero), mRuntimeMenu, -1, OnRuntimeMenuSelected, null);
         }
         else if (IsRequestParentOrChild)
         {
             RequestChild(null);
         }
         else
         {
             DisplayEditMenu(new Rect(Event.current.mousePosition, Vector2.zero));
         }
         return(true);
     }
     return(false);
 }
Exemplo n.º 8
0
 private bool InteractGraphKeyDown(KeyCode key)
 {
     if (key == KeyCode.Delete)
     {
         DeleteSelections();
         return(true);
     }
     else if (key == KeyCode.C && Event.current.control)
     {
         CopySelection();
         return(true);
     }
     else if (!Application.isPlaying && !Event.current.alt && !Event.current.control && !Event.current.shift &&
              mAssetBinder != null && mAssetBinder.targetTree != null)
     {
         mContextNode = RaycastNode;
         mContextPos  = AIGraph.CalculateLocalPosition(GlobalMousePosition);
         sHotkeyMenu.Display(this, new Rect(Event.current.mousePosition, Vector2.zero), key);
     }
     return(false);
 }
Exemplo n.º 9
0
 protected override void OnCanvasGUI()
 {
     base.OnCanvasGUI();
     BehaviourNode.SetFontScale(GraphCanvas.GlobalScale);
 }
Exemplo n.º 10
0
 protected override void OnCanvasStart()
 {
     BehaviourNode.InitGUIStyle();
     base.OnCanvasStart();
 }
Exemplo n.º 11
0
 public void RequestChild(BehaviourNode node)
 {
     PresentParentRequest = null;
     PresentChildRequest  = Application.isPlaying || TargetTree == null ? null : node;
 }
Exemplo n.º 12
0
 public override bool EnableParentAs(BehaviourNode node)
 {
     return(false);
 }
 public virtual void ModifyParentAs(BehaviourNode node)
 {
     editor.RequestParent(null);
 }
 public virtual bool EnableParentAs(BehaviourNode node)
 {
     return(enableParent && node == null || (node.enableChild && node != this));
 }