コード例 #1
0
        public void Visit(BehaviourTreeRunner btree)
        {
#if UNITY_EDITOR
            if (BreakToggle)
            {
                btree.NotifyBreakCallback(this);
            }
#endif
            mStartTime = Time.time;
            if (IsRunnable(btree))
            {
                for (int i = 0; i < ServiceLength; i++)
                {
                    BTServiceBase serv = mServices[i];
                    if (serv != null)
                    {
                        btree.StartService(serv);
                    }
                }
                mVisited = true;
                OnVisit(btree);
            }
            else
            {
                State = EBTTaskState.faild;
            }
        }
コード例 #2
0
 public void StartService(BTServiceBase service)
 {
     if (service != null)
     {
         mServices.AddLast(service);
         service.OnServiceStart(this);
     }
 }
コード例 #3
0
            public BTNodeBase Instantiate(BehaviourTreeRunner btree, BehaviourTreeAsset asset)
            {
                BTNodeBase node = null;

                if (m_Type == EBTNodeType.task)
                {
                    node = new BTTask(m_Id, BehaviourLibrary.NewTask(m_Name, m_Id));
                }
                else if (m_Type == EBTNodeType.controller)
                {
                    node = BehaviourLibrary.NewController(m_Name, m_Id);
                }
                if (node != null)
                {
                    node.InitData(btree, m_JsonData);
                    node.InitDecoratorSize(m_Conditions == null ? 0 : m_Conditions.Length, m_Children == null ? 0 : m_Children.Length, m_Services == null ? 0 : m_Services.Length);
                    for (int i = 0; i < node.ConditionLength; i++)
                    {
                        BTData data = asset.GetDataById(m_Conditions[i]);
                        if (data == null)
                        {
                            continue;
                        }
                        node.SetNotFlag(i, data.m_NotFlag);
                        BTConditionBase cond = BehaviourLibrary.NewCondition(data.m_Name, data.m_Id);
                        if (cond != null)
                        {
                            cond.OnInitData(btree, data.m_JsonData);
                            node.SetCondition(i, cond);
                        }
                    }
                    for (int i = 0; i < node.ServiceLength; i++)
                    {
                        BTData data = asset.GetDataById(m_Services[i]);
                        if (data == null)
                        {
                            continue;
                        }
                        BTServiceBase serv = BehaviourLibrary.NewService(data.m_Name, data.m_Id);
                        if (serv != null)
                        {
                            serv.OnInitData(btree, data.m_JsonData);
                            node.SetService(i, serv);
                        }
                    }
                }
                return(node);
            }
コード例 #4
0
 public void Cleanup(BehaviourTreeRunner btree)
 {
     if (mVisited)
     {
         mVisited = false;
         mEndTime = Time.time;
         for (int i = ServiceLength - 1; i >= 0; i--)
         {
             BTServiceBase serv = mServices[i];
             if (serv != null)
             {
                 btree.StopService(serv);
             }
         }
         OnCleanup(btree);
     }
 }
コード例 #5
0
 public void StopService(BTServiceBase service)
 {
     if (service != null)
     {
         service.OnServiceStop(this);
         LinkedListNode <BTServiceBase> serv = mServices.Last;
         while (serv != null)
         {
             if (serv.Value == service)
             {
                 mServices.Remove(serv);
                 break;
             }
             serv = serv.Previous;
         }
     }
 }
コード例 #6
0
 public virtual void SetService(int index, BTServiceBase service)
 {
     mServices[index] = service;
 }