示例#1
0
        public override STATUS Execute()
        {
            Debug.Log("[ProbabilityBT]");
            STATUS finalStatus;
            // This means that in the previous execution the choosen node
            // returned RUNNING
            if(mp_CurrentNode != null)
            {
                finalStatus = mp_CurrentNode.Execute();
                if(finalStatus != STATUS.RUNNING)
                    mp_CurrentNode = null;
                return finalStatus;
            }

            Init();

            float randomWeight = Random.Range(0f, mf_TotalWeigth);
            float weightSum = 0f;
            foreach(KeyValuePair<BehaviorTreeNode, float> weightTuple in md_WeightList)
            {
                weightSum += weightTuple.Value;
                if(randomWeight <= weightSum)
                {
                    mp_CurrentNode = weightTuple.Key;
                    finalStatus = mp_CurrentNode.Execute();
                    if(finalStatus != STATUS.RUNNING)
                        mp_CurrentNode = null;
                    return finalStatus;
                }
            }
            return STATUS.ERROR;
        }
示例#2
0
        public override STATUS Execute()
        {
            Debug.Log("[ProbabilityBT]");
            STATUS finalStatus;

            // This means that in the previous execution the choosen node
            // returned RUNNING
            if (mp_CurrentNode != null)
            {
                finalStatus = mp_CurrentNode.Execute();
                if (finalStatus != STATUS.RUNNING)
                {
                    mp_CurrentNode = null;
                }
                return(finalStatus);
            }

            Init();

            float randomWeight = Random.Range(0f, mf_TotalWeigth);
            float weightSum    = 0f;

            foreach (KeyValuePair <BehaviorTreeNode, float> weightTuple in md_WeightList)
            {
                weightSum += weightTuple.Value;
                if (randomWeight <= weightSum)
                {
                    mp_CurrentNode = weightTuple.Key;
                    finalStatus    = mp_CurrentNode.Execute();
                    if (finalStatus != STATUS.RUNNING)
                    {
                        mp_CurrentNode = null;
                    }
                    return(finalStatus);
                }
            }
            return(STATUS.ERROR);
        }