コード例 #1
0
        //public void AddDelayTask(int id, System.Action act)
        //{
        //    if (act == null)
        //        return;
        //    for (int i = 0; i < mPostTasks.Count; i++)
        //    {
        //        if (mPostTasks[i].Id == id)
        //        {
        //            mPostTasks[i].Act = act;
        //            return;
        //        }
        //    }
        //    mPostTasks.Add(new DelayTask(id, act));
        //}

        void ResetIdCounter()
        {
            mIdCounter = 0;
            for (int i = 0; i < TreeGraph.NodeLength; i++)
            {
                BehaviourNodeGUI node = TreeGraph[i] as BehaviourNodeGUI;
                if (node == null || node.Self == null)
                {
                    continue;
                }
                if (node.Self.BTId > mIdCounter)
                {
                    mIdCounter = node.Self.BTId;
                }
                for (int j = 0; j < node.conditions.Count; j++)
                {
                    BehaviourNodeGUI.Decorator deco = node.conditions[j];
                    if (deco != null && deco.BTId > mIdCounter)
                    {
                        mIdCounter = deco.BTId;
                    }
                }
                for (int j = 0; j < node.services.Count; j++)
                {
                    BehaviourNodeGUI.Decorator deco = node.services[j];
                    if (deco != null && deco.BTId > mIdCounter)
                    {
                        mIdCounter = deco.BTId;
                    }
                }
            }
        }
コード例 #2
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);
        }
コード例 #3
0
 void BindBehaviourTreeEvent(bool bind)
 {
     if (Runner == null)
     {
         return;
     }
     if (bind)
     {
         Runner.OnBehaviourTreeBegin += OnBehaviourTreeBegin;
         Runner.OnBehaviourTreeFrame += OnBehaviourTreeFrame;
         for (int i = 0; i < TreeCanvas.ElementCount; i++)
         {
             BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i);
             if (node == null)
             {
                 continue;
             }
             node.RuntimeNode = Runner.FindRuntimeNode(node.Self.BTId);
         }
     }
     else
     {
         Runner.OnBehaviourTreeBegin -= OnBehaviourTreeBegin;
         Runner.OnBehaviourTreeFrame -= OnBehaviourTreeFrame;
         for (int i = 0; i < TreeCanvas.ElementCount; i++)
         {
             BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i);
             if (node == null)
             {
                 continue;
             }
             node.RuntimeNode = null;
         }
     }
 }
コード例 #4
0
 public override void OnGUI(Rect clipRect)
 {
     if (!Visible)
     {
         return;
     }
     mResizeNode = false;
     QuickGUI.DrawBox(GlobalRect, new Color(0.3f, 0.3f, 0.3f), Color.black, 2, true);
     //GUI.Label(GlobalRect, "", "sv_iconselector_back");
     if (Mode == EMode.alter_node)
     {
         OnContextDecoratorGUI();
         OnDecoratorsListGUI();
     }
     else if (Mode == EMode.new_node)
     {
         OnNewNodeGUI();
     }
     //GUI.Label(GlobalRect, "", "Icon.OutlineBorder");
     if (mResizeNode)
     {
         BehaviourNodeGUI node = Context as BehaviourNodeGUI;
         if (node != null)
         {
             node.Resize();
         }
         mResizeNode = false;
     }
     if (!Visible)
     {
         Hide();
     }
 }
コード例 #5
0
        BehaviourNodeGUI NewNode(BTData data)
        {
            BehaviourMeta meta = BehaviourModuleManager.GetOrNewInstance().FindBTMeta(data.m_Type, data.m_Name);

            if (meta == null || (meta.NodeType != EBTNodeType.task && meta.NodeType != EBTNodeType.controller))
            {
                return(null);
            }
            BehaviourNodeGUI bnode = new BehaviourNodeGUI(this);

            bnode.Self = new BehaviourNodeGUI.Decorator(data.m_Id, meta);
            bnode.Self.ParseData(data.m_JsonData);
            if (data.m_Services != null)
            {
                for (int i = 0; i < data.m_Services.Length; i++)
                {
                    BTData serv = BehaviourAsset.GetDataById(data.m_Services[i]);
                    if (serv == null)
                    {
                        continue;
                    }
                    BehaviourMeta bm = BehaviourModuleManager.GetOrNewInstance().FindBTMeta(EBTNodeType.service, serv.m_Name);
                    if (bm != null)
                    {
                        BehaviourNodeGUI.Decorator decor = new BehaviourNodeGUI.Decorator(serv.m_Id, bm);
                        decor.ParseData(serv.m_JsonData);
                        bnode.services.Add(decor);
                    }
                }
            }
            if (data.m_Conditions != null)
            {
                for (int i = 0; i < data.m_Conditions.Length; i++)
                {
                    BTData cond = BehaviourAsset.GetDataById(data.m_Conditions[i]);
                    if (cond == null)
                    {
                        continue;
                    }
                    BehaviourMeta bm = BehaviourModuleManager.GetOrNewInstance().FindBTMeta(EBTNodeType.condition, cond.m_Name);
                    if (bm != null)
                    {
                        BehaviourNodeGUI.Decorator decor = new BehaviourNodeGUI.Decorator(cond.m_Id, bm);
                        decor.NotFlag = cond.m_NotFlag;
                        decor.ParseData(cond.m_JsonData);
                        bnode.conditions.Add(decor);
                    }
                }
            }
            Rect r = new Rect();

            r.size          = bnode.CalculateLocalSize();
            r.position      = data.m_Pos - Vector2.right * r.size.x * 0.5f;
            bnode.LocalRect = r;
            return(bnode);
        }
コード例 #6
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);
            }
        }
コード例 #7
0
 public void SelectNodes(FilterDelegate <BehaviourNodeGUI> selector)
 {
     for (int i = 0; i < TreeCanvas.ElementCount; i++)
     {
         BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i);
         if (node != null)
         {
             node.IsSelected = selector(node);
         }
     }
 }
コード例 #8
0
 public void EditNodes(EditDelegate <BehaviourNodeGUI> editor)
 {
     for (int i = 0; i < TreeCanvas.ElementCount; i++)
     {
         BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i);
         if (node != null)
         {
             editor(node);
         }
     }
 }
コード例 #9
0
 bool CanLinkBetween(BehaviourNodeGUI from, BehaviourNodeGUI to)
 {
     if (from == null || to == null || from == to)
     {
         return(false);
     }
     if (mWindow.TreeGraph.FindPath(0, to, from))
     {
         return(false);
     }
     return(true);
 }
コード例 #10
0
 void SetNodeRuntimeState(int nodeId, EBTTaskState state)
 {
     for (int i = 0; i < TreeGraph.NodeLength; i++)
     {
         BehaviourNodeGUI node = TreeGraph[i] as BehaviourNodeGUI;
         if (node != null && node.Self.BTId == nodeId)
         {
             node.Self.BTRuntimeState = state;
             return;
         }
     }
 }
コード例 #11
0
        public void ShowContext(BehaviourNodeGUI context)
        {
            if (EditorApplication.isPlaying || context == null)
            {
                return;
            }
            List <BehaviourMeta> lst;

            if (mDecoratorList.Count < 2 || !BehaviourModuleManager.GetOrNewInstance().Decorators.Contains(mDecoratorList[1].BTMeta))
            {
                mMinDecoratorWidth = 200;
                mDecoratorList.Clear();
                lst = BehaviourModuleManager.GetOrNewInstance().Decorators;
                string category = null;
                for (int i = 0; i < lst.Count; i++)
                {
                    MetaUI m = new MetaUI(lst[i]);
                    if (m.BTMeta.Category != category)
                    {
                        category      = m.BTMeta.Category;
                        mDropDownMeta = new MetaUI(category);
                        mDecoratorList.Add(mDropDownMeta);
                    }
                    mDecoratorList.Add(m);
                    mMinDecoratorWidth = Mathf.Max(mMinDecoratorWidth, m.Width);
                }
            }

            Mode    = EMode.alter_node;
            Visible = true;
            Context = context;
            Rect rect = new Rect();

            rect.size = new Vector2(mMinDecoratorWidth + mMinTaskWidth, 270);
            Vector2 gsize = rect.size * GlobalScale;
            Vector2 delta = Vector2.zero;

            if (mWindow.GlobalMousePosition.y + gsize.y > mWindow.RootCanvas.GlobalRect.height)
            {
                delta.y = -rect.size.y;
            }
            if (mWindow.GlobalMousePosition.x + gsize.x > mWindow.RootCanvas.GlobalRect.width)
            {
                delta.x = -rect.size.x;
            }
            rect.position = Parent.CalculateLocalPosition(mWindow.GlobalMousePosition) + delta;
            LocalRect     = rect;
            mWindow.SelectNodes((x) => x == context);
            mDragEnd = true;
        }
コード例 #12
0
 private void OnBehaviourTreeFrame(BehaviourTreeRunner btree)
 {
     if (btree == Runner)
     {
         for (int i = 0; i < TreeCanvas.ElementCount; i++)
         {
             BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i);
             if (node != null)
             {
                 node.SyncRuntimeState(btree);
             }
         }
     }
 }
コード例 #13
0
        void ExportTreeData()
        {
            List <BTData>       nodes    = new List <BTData>();
            List <PaintElement> children = new List <PaintElement>();
            int rootId = 0;

            for (int i = 0; i < TreeCanvas.ElementCount; i++)
            {
                BehaviourNodeGUI bnode = TreeCanvas.GetElement <BehaviourNodeGUI>(i);
                if (bnode == null)
                {
                    continue;
                }
                if (TreeGraph.GetParent(0, bnode) == mRootGUI)
                {
                    rootId = bnode.Self.BTId;
                }
                BTData data = bnode.ExportNodeData(nodes);

                children.Clear();
                TreeGraph.GetAllChildren(0, bnode, children);
                GlobalUtil.Sort(children, (x, y) => x.LocalRect.center.x <= y.LocalRect.center.x ? -1 : 1);
                data.m_Children = new int[children.Count];
                for (int j = 0; j < children.Count; j++)
                {
                    BehaviourNodeGUI child = children[j] as BehaviourNodeGUI;
                    data.m_Children[j] = child == null ? 0 : child.Self.BTId;
                }
            }
            BehaviourAsset.m_RootNodeId = rootId;
            GlobalUtil.Sort(nodes, (x, y) => x.m_Id - y.m_Id);
            BehaviourAsset.m_Datas  = nodes.ToArray();
            BehaviourAsset.m_Sorted = true;

            BehaviourTreeAsset.Comment[] comments = new BehaviourTreeAsset.Comment[CommentCanvas.ElementCount];
            for (int i = 0; i < comments.Length; i++)
            {
                comments[i] = new BehaviourTreeAsset.Comment();
                BehaviourCommentGUI com = CommentCanvas.GetElement <BehaviourCommentGUI>(i);
                if (com != null)
                {
                    comments[i].m_Rect    = com.LocalRect;
                    comments[i].m_Comment = com.Comment ?? "";
                }
            }
            BehaviourAsset.m_Comments = comments;
            EditorUtility.SetDirty(BehaviourAsset);
        }
コード例 #14
0
 void GetContainsTarget()
 {
     targets.Clear();
     for (int i = 0; i < mWindow.TreeCanvas.ElementCount; i++)
     {
         BehaviourNodeGUI node = mWindow.TreeCanvas.GetElement <BehaviourNodeGUI>(i);
         if (node == null)
         {
             continue;
         }
         if (GlobalRect.Contains(node.GlobalRect.min) && GlobalRect.Contains(node.GlobalRect.max))
         {
             targets.Add(node);
         }
     }
 }
コード例 #15
0
        void VisitChildren(List <BehaviourNodeGUI> nodes, BehaviourNodeGUI root)
        {
            nodes.Add(root);
            List <PaintElement> children = new List <PaintElement>();

            TreeGraph.GetAllChildren(0, root, children);
            GlobalUtil.Sort(children, (x, y) => x.LocalRect.center.x <= y.LocalRect.center.x ? -1 : 1);
            for (int i = 0; i < children.Count; i++)
            {
                BehaviourNodeGUI node = children[i] as BehaviourNodeGUI;
                if (node != null)
                {
                    VisitChildren(nodes, node);
                }
            }
        }
コード例 #16
0
        // 附加到对象的装饰节点
        void OnAttachedDecoratorListGUI(ref Rect r, Vector2 tsize, Vector2 dsize, BehaviourNodeGUI node, List <BehaviourNodeGUI.Decorator> decorators)
        {
            Rect btn = new Rect();

            btn.size = Vector2.one * Mathf.Clamp(20 * GlobalScale, 15, 30);
            Rect tmp = new Rect();

            for (int i = 0; i < decorators.Count; i++)
            {
                BehaviourNodeGUI.Decorator decor = decorators[i];
                float h = (tsize.y + dsize.y) * decor.Properties.Length + tsize.y + tsize.y - dsize.y;
                r.height = h;
                bool inter = r.Contains(Event.current.mousePosition);
                //GUI.Label(r, "", inter ? "flow node 0" : "sv_iconselector_back");
                QuickGUI.DrawBox(r, new Color(0.3f, 0.3f, 0.3f), inter ? Color.yellow : Color.black, inter ? 2 : 0);
                Texture icon = decor.BTMeta.Icon;
                if (icon != null)
                {
                    tmp.size     = Vector2.one * tsize.y;
                    tmp.position = new Vector2(r.xMin + 1, r.yMin + 1);
                    GUI.DrawTexture(tmp, icon, ScaleMode.ScaleToFit);
                }
                if (inter)//|| mFocusDecorator == decorators[i])
                {
                    mRaycastDecorator = decor;
                }
                tmp.size     = tsize;
                tmp.position = new Vector2(r.xMin, r.yMin);
                Installizer.contentStyle.alignment = TextAnchor.MiddleCenter;
                Installizer.contentStyle.fontSize  = (int)Mathf.Max(1, 12f * GlobalScale);
                Installizer.contentContent.text    = decor.NotFlag?decor.BTMeta.NotDisplayName: decor.BTMeta.DisplayName;
                GUI.Label(tmp, Installizer.contentContent, Installizer.contentStyle);
                btn.center = new Vector2(tmp.xMax - btn.size.x * 0.5f, tmp.center.y);
                if (tsize.y > 8 && inter && GUI.Button(btn, "", "WinBtnCloseActiveMac"))
                {
                    node.RemoveDecorator(decor.BTMeta);
                    mResizeNode = true;
                    break;
                }
                tmp.size     = dsize;
                tmp.position = new Vector2(r.xMin, r.yMin + tsize.y);
                OnPropertiesList(tmp, decor, tsize, dsize);
                r.position += Vector2.up * h;
            }
            r.height = 0;
        }
コード例 #17
0
        void OnDecoratorsListGUI()
        {
            mRaycastMeta = null;
            Vector2          tsize = new Vector2(mMinDecoratorWidth * GlobalScale, 30 * GlobalScale);
            Vector2          dsize = new Vector2(mMinDecoratorWidth * GlobalScale, 20 * GlobalScale);
            BehaviourNodeGUI node  = Context as BehaviourNodeGUI;
            Rect             r     = new Rect();
            float            delta = 0;

            r.size     = new Vector2(tsize.x, 22);
            r.position = new Vector2(GlobalRect.xMax - tsize.x, GlobalRect.yMin + 2);
            if (OnSearchFieldGUI(r))
            {
                delta += 22;
            }
            bool search = !string.IsNullOrEmpty(mSearchContext);

            r.size     = new Vector2(tsize.x, GlobalRect.height - delta);
            r.position = new Vector2(GlobalRect.xMax - tsize.x, GlobalRect.yMin + 20);
            OnMetaList(mDecoratorList, r, search, true);
        }
コード例 #18
0
        void OnMetaList(List <MetaUI> metas, Rect r, bool search, bool skipExist)
        {
            Vector2 dsize = new Vector2(r.width, BehaviourNodeGUI.SUB_FONT_SIZE * GlobalScale);

            dsize.y += 10 * GlobalScale;
            Vector2 tsize = new Vector2(dsize.x, dsize.y * 1.2f);

            BeginScroll(r, ref mScrollRect);

            Installizer.contentStyle.fontSize = (int)Mathf.Max(1, BehaviourNodeGUI.SUB_FONT_SIZE * GlobalScale);
            r.size     = tsize;
            r.position = new Vector2(0, mScrollOffset);

            // controllers
            r.size = dsize;
            int len = metas.Count;

            Installizer.contentStyle.alignment = TextAnchor.MiddleCenter;
            BehaviourNodeGUI context = Context as BehaviourNodeGUI;
            Color            color   = Color.gray;
            bool             collape = false;

            for (int i = 0; i < len; i++)
            {
                MetaUI meta = metas[i];
                if (!meta.IsTitle)
                {
                    if (collape && !search)
                    {
                        continue;
                    }
                    if (search && !meta.BTMeta.SearchName.Contains(mSearchContext))
                    {
                        continue;
                    }
                    if (skipExist && context != null && context.ContainsDecorator(meta.BTMeta))
                    {
                        continue;
                    }
                }
                else
                {
                    collape = meta.Collaped;// != mDropDownMeta;
                }
                r.height = meta.Height * GlobalScale;
                if (r.yMax >= 0 && r.yMin < GlobalRect.height)
                {
                    bool inter = r.Contains(Event.current.mousePosition);
                    if (inter)
                    {
                        //GUI.Label(r, "", "flow node 0");// "Icon.ClipSelected");
                        mRaycastMeta = meta;//SelectionRect
                    }
                    meta.OnGUI(r, GlobalScale);
                    //QuickGUI.DrawBox(r, new Color(0.3f, 0.3f, 0.3f), Color.yellow, inter ? 2 : 0);
                    //Installizer.contentContent.text = meta.DisplayName;
                    //GUI.Label(r, Installizer.contentContent, Installizer.contentStyle);
                }
                r.y += meta.Height * GlobalScale;
            }

            EndScroll(r.yMax, ref mScrollRect, ref mScrollOffset);
        }
コード例 #19
0
        public override bool InteractMouseClick(EMouseButton button, Vector2 mousePosition)
        {
            if (!Visible)
            {
                return(false);
            }
            mFocusSearch = mRaycastSearch;
            if (mRaycastMeta != null && button == EMouseButton.left)
            {
                if (mRaycastMeta.IsTitle)
                {
                    mRaycastMeta.Collaped = !mRaycastMeta.Collaped;
                }
                //mDropDownMeta = mRaycastMeta == mDropDownMeta ? null : mRaycastMeta;
                else
                {
                    switch (mRaycastMeta.BTMeta.NodeType)
                    {
                    case EBTNodeType.task:
                    case EBTNodeType.controller:
                        mWindow.AddChild(Context, mRaycastMeta.BTMeta, new Vector2(LocalRect.center.x, LocalRect.yMin));
                        Hide();
                        return(true);

                    case EBTNodeType.condition:
                    case EBTNodeType.service:
                        BehaviourNodeGUI node = Context as BehaviourNodeGUI;
                        if (node != null)
                        {
                            BehaviourNodeGUI.Decorator decor = node.AddDecorator(mRaycastMeta.BTMeta);
                            if (decor != null && decor.Properties.Length > 0)
                            {
                                //mFocusDecorator = decor;
                                decor.UpdatePropertiesInfo();
                            }
                            //Hide();
                            node.Resize();
                            if (decor == null)
                            {
                                EditorCanvasTip.NewTip("不能添加<color=yellow>" + mRaycastMeta.BTMeta.DisplayName + "</color>", 2)
                                .Show(mWindow.RootCanvas, mWindow.RootCanvas.CalculateLocalPosition(mousePosition - Vector2.up * 20));
                            }
                        }
                        return(true);

                    default:
                        break;
                    }
                }
            }
            bool act = mFocusProperty == null && mRaycastProperty == null;

            if (mFocusProperty != mRaycastProperty)
            {
                SubmitProperty();
            }
            mFocusProperty  = mRaycastProperty;
            mFocusDecorator = mRaycastDecorator;
            if (act && mRaycastDecorator != null && mRaycastDecorator.BTMeta.NodeType == EBTNodeType.condition)
            {
                mRaycastDecorator.NotFlag = !mRaycastDecorator.NotFlag;
            }
            //if (mRaycastDecorator != null && mRaycastDecorator.Properties.Length > 0)
            //{
            //    mFocusDecorator = mRaycastDecorator;
            //}
            return(Visible);
        }
コード例 #20
0
        public override void OnGUI(Rect clipRect)
        {
            //DrawGridLine(clipRect);
            int   len   = mWindow.TreeGraph.PathLength(0);
            float width = GlobalScale * 5;

            if (EditorApplication.isPlaying)
            {
                width *= 1.7f;
            }
            width = Mathf.Clamp(width, 1, 20);
            float        height = 20 * GlobalScale;
            int          from, to;
            Vector2      start;
            Vector2      end;
            PaintElement a, b;
            Color        c = color;

            for (int i = 0; i < len; i++)
            {
                mWindow.TreeGraph.PathAt(0, i, out from, out to);
                a = mWindow.TreeGraph[from];
                b = mWindow.TreeGraph[to];
                if (b == mWindow.EditTarget && mWindow.EditMode == BehaviourTreeDesignerWindow.ENodeEditMode.modify_parent)
                {
                    continue;
                }
                start.x = a.GlobalRect.center.x;
                start.y = a.GlobalRect.yMax;
                end.x   = b.GlobalRect.center.x;
                end.y   = b.GlobalRect.yMin;
                if (EditorApplication.isPlaying)
                {
                    BehaviourNodeGUI bb = b as BehaviourNodeGUI;
                    if (bb != null && bb.Self.BTRuntimeState != Devil.AI.EBTTaskState.inactive)
                    {
                        c = bb.Self.BTRuntimeState == Devil.AI.EBTTaskState.success ? Color.green : (bb.Self.BTRuntimeState == Devil.AI.EBTTaskState.running ? Color.blue : Color.red);
                    }
                    else
                    {
                        c = color;
                    }
                }
                ConnectNode(start, end, c, width, height);
            }
            if (mWindow.EditTarget != null)
            {
                start.x = mWindow.EditTarget.GlobalRect.center.x;
                if (mWindow.EditMode == BehaviourTreeDesignerWindow.ENodeEditMode.modify_child)
                {
                    start.y = mWindow.EditTarget.GlobalRect.yMax;
                    ConnectNode(start, mWindow.GlobalMousePosition, Color.yellow, width, height);
                }
                else if (mWindow.EditMode == BehaviourTreeDesignerWindow.ENodeEditMode.modify_parent)
                {
                    start.y = mWindow.EditTarget.GlobalRect.yMin;
                    ConnectNode(mWindow.GlobalMousePosition, start, Color.yellow, width, height);
                }
            }
            else if (mWindow.ContextMenu.Mode == BehaviourTreeContextMenuGUI.EMode.new_node && mWindow.ContextMenu.Context != null)
            {
                a       = mWindow.ContextMenu.Context;
                start.x = a.GlobalRect.center.x;
                start.y = a.GlobalRect.yMax;
                end     = mWindow.ContextMenu.AttachPoint;
                ConnectNode(start, end, Color.yellow, width, height);
            }
        }
コード例 #21
0
        void OnContextDecoratorGUI()
        {
            mRaycastProperty  = null;
            mRaycastDecorator = null;
            float l = Mathf.Max(mMinTaskWidth, mMinDecoratorWidth);
            float w = l + mMinDecoratorWidth;

            if (w > LocalRect.width)
            {
                Rect rect = new Rect();
                rect.size     = new Vector2(w, LocalRect.height);
                rect.position = new Vector2(LocalRect.center.x - w * 0.5f, LocalRect.yMin);
                LocalRect     = rect;
            }
            Vector2 dsize = new Vector2(l * GlobalScale - 2, BehaviourNodeGUI.SUB_FONT_SIZE * GlobalScale);

            dsize.y += 5 * GlobalScale;
            Vector2 tsize = new Vector2(dsize.x, dsize.y * 1.3f);

            BehaviourNodeGUI node  = Context as BehaviourNodeGUI;
            TextAnchor       align = Installizer.contentStyle.alignment;

            Rect r = new Rect();

            r.size     = new Vector2(tsize.x, GlobalRect.height);
            r.position = GlobalRect.position;
            BeginScroll(r, ref mScrollRectL);

            //
            r.size     = tsize;
            r.position = new Vector2(0, mScrollOffsetL);
            BTInputProperty[] properties;
            // conditions
            OnAttachedDecoratorListGUI(ref r, tsize, dsize, node, node.conditions);
            // self
            properties = node.Self.Properties;
            r.size     = new Vector2(tsize.x, tsize.y + properties.Length * (tsize.y + dsize.y) + tsize.y);
            QuickGUI.DrawBox(r, node.Self.BTMeta.color, Color.black);
            if (r.Contains(Event.current.mousePosition))
            {
                mRaycastDecorator = node.Self;
            }
            Rect    tmp  = new Rect();
            Texture icon = node.Self.BTMeta.Icon;

            if (icon != null)
            {
                tmp.size     = Vector2.one * tsize.y;
                tmp.position = new Vector2(r.xMin + 1, r.yMin + 1);
                GUI.DrawTexture(tmp, icon, ScaleMode.ScaleToFit);
            }
            tmp.size     = tsize;
            tmp.position = new Vector2(r.xMin, r.yMin);
            Installizer.titleStyle.alignment = TextAnchor.MiddleCenter;
            Installizer.titleStyle.fontSize  = (int)Mathf.Max(1, BehaviourNodeGUI.FONT_SIZE * GlobalScale);
            Installizer.titleContent.text    = string.Format("<b>{0}</b>", node.Self.BTMeta.DisplayName);
            GUI.Label(tmp, Installizer.titleContent, Installizer.titleStyle);
            tmp.y += tsize.y + 4 * GlobalScale;
            OnPropertiesList(tmp, node.Self, tsize, dsize);
            r.y = r.yMax;
            //services
            OnAttachedDecoratorListGUI(ref r, tsize, dsize, node, node.services);

            EndScroll(r.yMax, ref mScrollRectL, ref mScrollOffsetL);

            Handles.color = Color.gray;
            Handles.DrawLine(new Vector3(GlobalRect.xMin + tsize.x, GlobalRect.yMin),
                             new Vector3(GlobalRect.xMin + tsize.x, GlobalRect.yMax));
            Installizer.contentStyle.alignment = align;
        }