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);
            }
Esempio n. 2
0
        public bool IsOnCondition(BehaviourTreeRunner runner)
        {
            for (int i = 0; i < ConditionLength; i++)
            {
                BTConditionBase decor = GetCondition(i);
                if (decor != null && !(decor.IsTaskOnCondition(runner) ^ GetNotFlag(i)))
                {
#if UNITY_EDITOR
                    ConditionBuffer[i] = false;
                    for (int k = i + 1; k < ConditionLength; k++)
                    {
                        decor = GetCondition(k);
                        ConditionBuffer[k] = decor == null ? false : decor.IsTaskRunnable(runner);
                    }
#endif
                    return(false);
                }
#if UNITY_EDITOR
                ConditionBuffer[i] = true;
#endif
            }
            return(true);
        }
Esempio n. 3
0
 public virtual void SetCondition(int index, BTConditionBase condition)
 {
     mConditions[index] = condition;
 }