示例#1
0
 protected virtual void OnDestroy()
 {
     if (sInstance == this)
     {
         sInstance = null;
     }
 }
            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);
            }
示例#3
0
 protected virtual void Awake()
 {
     sInstance = this;
     if (m_DontDestroyOnLoad)
     {
         DontDestroyOnLoad(gameObject);
     }
     if (m_GlobalBlackboard == null)
     {
         mBlackboard = new BTBlackboard();
     }
     else
     {
         mBlackboard = new BTBlackboard(m_GlobalBlackboard);
     }
     mTasks       = new Dictionary <string, BTGenerator <BTTaskBase> >();
     mConditions  = new Dictionary <string, BTGenerator <BTConditionBase> >();
     mServices    = new Dictionary <string, BTGenerator <BTServiceBase> >();
     mControllers = new Dictionary <string, BTGenerator <BTNodeBase> >();
     OnInit();
 }