Ejemplo n.º 1
0
        public BehaviourNodeGUI AddChild(PaintElement parent, BehaviourMeta meta, Vector2 localPos)
        {
            if (parent != null && parent.Parent != TreeCanvas)
            {
                return(null);
            }
            BehaviourNodeGUI node = new BehaviourNodeGUI(this);

            node.Self = new BehaviourNodeGUI.Decorator(GenerateId, meta);
            node.Self.UpdatePropertiesInfo();
            Rect r = new Rect();

            r.size         = node.CalculateLocalSize();
            r.position     = localPos - Vector2.right * r.size.x * 0.5f;
            node.LocalRect = r;
            TreeCanvas.AddElement(node);
            TreeGraph.AddNode(node);
            if (parent != null)
            {
                TreeGraph.AddPath(0, parent, node);
            }
            RebuildExecutionOrder();

            return(node);
        }
Ejemplo n.º 2
0
        public void InitWith(BehaviourTreeRunner runner)
        {
            if (EditorApplication.isPlaying)
            {
                BindBehaviourTreeEvent(false);
            }
            ContextMenu.Hide();
            Runner         = runner;
            BehaviourAsset = Runner == null ? (Selection.activeObject as BehaviourTreeAsset) : Runner.SourceAsset;
            TreeCanvas.ClearElements();
            CommentCanvas.ClearElements();
            TreeGraph.Clear();

            mRootGUI = new BehaviourRootGUI(this);
            mRootGUI.UpdateLocalData();
            TreeCanvas.AddElement(mRootGUI);
            TreeGraph.AddNode(mRootGUI);

            if (BehaviourAsset != null)
            {
                ImportTreeData();
            }
            ResetIdCounter();
            RebuildExecutionOrder();
            UpdateStateInfo();
            if (EditorApplication.isPlaying)
            {
                BindBehaviourTreeEvent(true);
            }
        }
Ejemplo n.º 3
0
        void ImportTreeData()
        {
            for (int i = 0; i < BehaviourAsset.m_Datas.Length; i++)
            {
                BehaviourNodeGUI node = NewNode(BehaviourAsset.m_Datas[i]);
                if (node != null)
                {
                    TreeGraph.AddNode(node);
                    TreeCanvas.AddElement(node);
                }
            }
            int id = 0;
            FilterDelegate <PaintElement> filter = (x) =>
            {
                BehaviourNodeGUI bx = x as BehaviourNodeGUI;
                return(bx != null && bx.Self.BTId == id);
            };

            for (int i = 0; i < BehaviourAsset.m_Datas.Length; i++)
            {
                BTData data = BehaviourAsset.m_Datas[i];
                id = data.m_Id;
                BehaviourNodeGUI gnode = TreeGraph.FindNode(filter) as BehaviourNodeGUI;
                if (gnode == null)
                {
                    continue;
                }
                int len = data.m_Children == null ? 0 : data.m_Children.Length;
                for (int j = 0; j < len; j++)
                {
                    id = data.m_Children[j];
                    BehaviourNodeGUI gchild = TreeGraph.FindNode(filter) as BehaviourNodeGUI;
                    if (gchild != null)
                    {
                        TreeGraph.AddPath(0, gnode, gchild);
                    }
                }
            }
            id = BehaviourAsset.m_RootNodeId;
            BehaviourNodeGUI root = TreeGraph.FindNode(filter) as BehaviourNodeGUI;

            if (root != null)
            {
                TreeGraph.AddPath(0, mRootGUI, root);
            }

            for (int i = 0; i < BehaviourAsset.m_Comments.Length; i++)
            {
                BehaviourCommentGUI comment = new BehaviourCommentGUI(this);
                comment.Comment   = BehaviourAsset.m_Comments[i].m_Comment;
                comment.LocalRect = BehaviourAsset.m_Comments[i].m_Rect;
                CommentCanvas.AddElement(comment);
            }
        }