Пример #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
        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);
        }
Пример #3
0
 public void Hide()
 {
     if (mFocusProperty != null && mFocusProperty.ReguexData() && mFocusDecorator != null)
     {
         mFocusDecorator.UpdatePropertiesInfo();
     }
     Visible           = false;
     Context           = null;
     Mode              = EMode.none;
     mRaycastProperty  = null;
     mFocusProperty    = null;
     mFocusDecorator   = null;
     mRaycastDecorator = null;
     mDropDownMeta     = null;
     mSearchContext    = "";
 }
Пример #4
0
        void OnPropertiesList(Rect r, BehaviourNodeGUI.Decorator decorator, Vector2 tsize, Vector2 dsize)
        {
            BTInputProperty[] properties = decorator.Properties;
            if (properties.Length == 0)
            {
                return;
            }
            Rect h = new Rect();

            h.size     = new Vector2(dsize.x - 6 * GlobalScale, dsize.y);
            h.position = r.position + Vector2.one * 3 * GlobalScale;
            Installizer.contentStyle.alignment = TextAnchor.MiddleLeft;
            Installizer.contentStyle.fontSize  = (int)Mathf.Max(1, BehaviourNodeGUI.SUB_FONT_SIZE * GlobalScale);
            bool dirty = false;

            for (int i = 0; i < properties.Length; i++)
            {
                BTInputProperty prop = properties[i];
                Installizer.contentContent.text = prop.PropertyName;
                GUI.Label(h, Installizer.contentContent, Installizer.contentStyle);
                h.y += dsize.y;//  = new Vector2(r.xMin + x0, r.yMin + i * dsize.y);
                //GUI.Label(h, "", "textfield");// "TL LoopSection");
                QuickGUI.DrawBox(h, Color.clear, Color.gray, 1);
                if (h.Contains(Event.current.mousePosition))
                {
                    mRaycastProperty = prop;
                }
                if (mFocusProperty == prop)
                {
                    string str = GUI.TextField(h, prop.InputData, Installizer.contentStyle);
                    dirty         |= str != prop.InputData;
                    prop.InputData = str;
                }
                else
                {
                    prop.ReguexData();
                    GUI.Label(h, prop.IsDefaultValue ?
                              string.Format("<i><color=#a0a0a0>({0})</color></i> {1} ", prop.TypeName, prop.InputData) : prop.InputData, Installizer.contentStyle);
                }
                h.y += tsize.y;
            }
            if (dirty)
            {
                decorator.UpdatePropertiesInfo();
                mResizeNode = true;
            }
        }
Пример #5
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;
        }
Пример #6
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);
        }
Пример #7
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;
        }