示例#1
0
        public void Update(BehaviourTreeRunner runner, float deltaTime)
        {
            if (mRoot == null)
            {
                IsComplate = true;
                return;
            }
            if (RuntimeNode == null)
            {
                IsComplate = false;
#if UNITY_EDITOR
                runner.NotifyBehaviourTreeBegin();
#endif
                RuntimeNode = mRoot;
                RuntimeNode.Visit(runner);
            }
            else
            {
                RuntimeNode.Tick(runner, Time.deltaTime);
            }
            VisitChildren(runner, RuntimeNode);
            State = mRoot.State;
            if (RuntimeNode == null)
            {
                IsComplate = true;
            }
#if UNITY_EDITOR
            runner.NotifyBehaviourTreeFrame();
            if (IsComplate)
            {
                runner.NotifyBehaviourTreeEnd();
            }
#endif
        }
示例#2
0
 public void SyncRuntimeState(BehaviourTreeRunner btree)
 {
     if (RuntimeNode == null)
     {
         Self.BTRuntimeState = EBTTaskState.inactive;
         for (int i = 0; i < conditions.Count; i++)
         {
             conditions[i].BTRuntimeState = EBTTaskState.inactive;
         }
         for (int i = 0; i < services.Count; i++)
         {
             services[i].BTRuntimeState = EBTTaskState.inactive;
         }
     }
     else
     {
         Self.BTRuntimeState = RuntimeNode.State;
         for (int i = 0; i < RuntimeNode.ConditionBuffer.Length; i++)
         {
             conditions[i].BTRuntimeState = RuntimeNode.State == EBTTaskState.inactive ? EBTTaskState.inactive
                 : (RuntimeNode.ConditionBuffer[i] ? EBTTaskState.success : EBTTaskState.faild);
         }
         for (int i = 0; i < services.Count; i++)
         {
             EBTTaskState stat = services[i].BTRuntimeState;
             services[i].BTRuntimeState = btree.IsServiceActive(services[i].BTId) ? EBTTaskState.running : EBTTaskState.inactive;
             if (stat != EBTTaskState.running && services[i].BTRuntimeState == EBTTaskState.running)
             {
                 services[i].TimeOffset = btree.BehaviourTime;
             }
         }
     }
 }
示例#3
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;
         }
     }
 }
示例#4
0
 protected override void OnReturnWithState(BehaviourTreeRunner btree, EBTTaskState state)
 {
     if (state == EBTTaskState.faild || !IsOnCondition(btree))
     {
         this.State = EBTTaskState.faild;
     }
     else
     {
         mVisitIndex++;
         if (mVisitIndex >= ChildLength)
         {
             this.State = EBTTaskState.success;
         }
     }
 }
示例#5
0
 protected abstract void OnReturnWithState(BehaviourTreeRunner btree, EBTTaskState state);
示例#6
0
 public void ReturnWithState(BehaviourTreeRunner btree, EBTTaskState state)
 {
     OnReturnWithState(btree, state);
 }
示例#7
0
 protected override void OnReturnWithState(BehaviourTreeRunner btree, EBTTaskState state)
 {
 }
示例#8
0
        void OnDecoratorListGUI(List <Decorator> decors, ref Rect rect)
        {
            int   size0 = (int)Mathf.Max(1, SUB_FONT_SIZE * GlobalScale);
            int   size1 = (int)Mathf.Max(1, size0 * 0.95f);
            float h0;
            float h1;
            Rect  r  = new Rect();
            float x0 = rect.xMin;
            float x  = 5 * GlobalScale;

            r.size     = new Vector2(rect.width - x * 2, rect.height);
            r.position = new Vector2(x + x0, rect.yMax);
            Rect btn = new Rect();

            btn.size = Vector2.one * Mathf.Clamp(20 * GlobalScale, 15, 30);
            for (int i = 0; i < decors.Count; i++)
            {
                h0            = decors[i].TextHeight * GlobalScale;
                h1            = decors[i].SubTextHeight * GlobalScale;
                rect.height   = h0 + h1;
                rect.position = new Vector2(x0, r.yMin);
                if (rect.Contains(Event.current.mousePosition))
                {
                    mRaycastDecorator = decors[i];
                }
                bool sel = mWindow.EditMode == BehaviourTreeDesignerWindow.ENodeEditMode.none && !mWindow.ContextMenu.Visible && decors[i] == mRaycastDecorator && rect.height >= btn.height;
                QuickGUI.DrawBox(rect, new Color(0.3f, 0.3f, 0.3f), sel ? Color.yellow : Color.black, sel ? 3 : 0);
                //GUI.Label(rect, "", sel ? "flow node 0 on" : "flow node 0");
                if (decors[i].BTMeta.Icon != null)
                {
                    Rect tmp = new Rect(rect.x + 1, rect.y + 1, h0, h0);
                    GUI.DrawTexture(tmp, decors[i].BTMeta.Icon, ScaleMode.ScaleToFit);
                }
                EBTTaskState stat = mWindow.IsPlaying ? decors[i].BTRuntimeState : EBTTaskState.inactive;
                if (stat == EBTTaskState.success)
                {
                    QuickGUI.DrawBox(rect, Color.clear, Color.green, 2);
                }
                else if (stat == EBTTaskState.faild)
                {
                    QuickGUI.DrawBox(rect, Color.clear, Color.red, 2);
                }
                r.height = h0;
                Installizer.contentStyle.alignment        = TextAnchor.MiddleCenter;
                Installizer.contentStyle.fontSize         = size0;
                Installizer.contentStyle.normal.textColor = Color.white;
                Installizer.contentContent.text           = decors[i].NotFlag ? decors[i].BTMeta.NotDisplayName : decors[i].BTMeta.DisplayName;
                //Installizer.contentContent.text = string.Format("<color=white>{0}</color>", decors[i].BTMeta.DisplayName);
                GUI.Label(r, Installizer.contentContent, Installizer.contentStyle);
                r.position += Vector2.up * h0;
                if (!string.IsNullOrEmpty(decors[i].PropertiesInfo))
                {
                    Installizer.contentStyle.alignment = TextAnchor.MiddleLeft;
                    r.height = h1;
                    Installizer.contentStyle.fontSize         = size1;
                    Installizer.contentStyle.normal.textColor = new Color(0.7f, 0.7f, 0.7f);
                    Installizer.contentContent.text           = decors[i].PropertiesInfo;
                    GUI.Label(r, Installizer.contentContent, Installizer.contentStyle);
                    r.position += Vector2.up * h1;
                }
                if (!mWindow.IsPlaying && sel)
                {
                    btn.position = new Vector2(rect.xMax - btn.width, rect.yMin);
                    if (GUI.Button(btn, "", "WinBtnCloseActiveMac"))
                    {
                        RemoveDecorator(decors[i].BTMeta);
                        Resize();
                        break;
                    }
                }
                if (stat == EBTTaskState.running)
                {
                    Rect  process = rect;
                    float dx      = Mathf.PingPong((mWindow.Runner.BehaviourTime - decors[i].TimeOffset) * 0.3f, 2f);
                    process.xMax = Mathf.Lerp(rect.xMin, rect.xMax, Mathf.Clamp01(dx));
                    process.xMin = Mathf.Lerp(rect.xMin, rect.xMax, Mathf.Clamp01(dx - 1));
                    //GUI.Label(process, "", "U2D.createRect");
                    QuickGUI.DrawBox(process, Color.blue * 0.3f, Color.blue, 1, true);
                    //U2D.createRect
                }
            }
        }