Example #1
0
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

            initListTo <bool>(thisContext.evaluationStatus, false);
            bool finalResult = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BehaviourAction node = GetChild <BehaviourAction>(i);
                bool            ret  = node.Evaluate(wData);
                //early break
                if (_evaluationRelationship == ECHILDREN_RELATIONSHIP.AND && ret == false)
                {
                    finalResult = false;
                    break;
                }
                if (ret == true)
                {
                    finalResult = true;
                }
                thisContext.evaluationStatus[i] = ret;
            }
            return(finalResult);
        }
Example #2
0
        protected override int onUpdate(BehaviourTreeData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            int             runningStatus        = BehaviourTreeRunningStatus.FINISHED;
            BehaviourAction node = GetChild <BehaviourAction>(thisContext.currentSelectedIndex);

            runningStatus = node.Update(wData);
            if (_continueIfErrorOccors == false && BehaviourTreeRunningStatus.IsError(runningStatus))
            {
                thisContext.currentSelectedIndex = -1;
                return(runningStatus);
            }
            if (BehaviourTreeRunningStatus.IsFinished(runningStatus))
            {
                thisContext.currentSelectedIndex++;
                if (IsIndexValid(thisContext.currentSelectedIndex))
                {
                    runningStatus = BehaviourTreeRunningStatus.EXECUTING;
                }
                else
                {
                    thisContext.currentSelectedIndex = -1;
                }
            }
            return(runningStatus);
        }
Example #3
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            BehaviourAction          node        = GetChild <BehaviourAction>(thisContext.currentSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }
            thisContext.currentSelectedIndex = -1;
        }
Example #4
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);

            if (IsIndexValid(0))
            {
                BehaviourAction node = GetChild <BehaviourAction>(0);
                node.Transition(wData);
            }
            thisContext.currentCount = 0;
        }
Example #5
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BehaviourAction node = GetChild <BehaviourAction>(i);
                node.Transition(wData);
            }
            //clear running status
            initListTo <int>(thisContext.runningStatus, BehaviourTreeRunningStatus.EXECUTING);
        }
Example #6
0
 protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
 {
     BehaviourActionPrioritizedSelector.TBTActionPrioritizedSelectorContext thisContext =
         getContext <BehaviourActionPrioritizedSelector.TBTActionPrioritizedSelectorContext>(wData);
     //check last node first
     if (IsIndexValid(thisContext.currentSelectedIndex))
     {
         BehaviourAction node = GetChild <BehaviourAction>(thisContext.currentSelectedIndex);
         if (node.Evaluate(wData))
         {
             return(true);
         }
     }
     return(base.onEvaluate(wData));
 }
Example #7
0
        //-------------------------------------------------------
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);
            bool checkLoopCount = (_loopCount == INFINITY || thisContext.currentCount < _loopCount);

            if (checkLoopCount == false)
            {
                return(false);
            }
            if (IsIndexValid(0))
            {
                BehaviourAction node = GetChild <BehaviourAction>(0);
                return(node.Evaluate(wData));
            }
            return(false);
        }
Example #8
0
        protected override int onUpdate(BehaviourTreeData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

            //first time initialization
            if (thisContext.runningStatus.Count != GetChildCount())
            {
                initListTo <int>(thisContext.runningStatus, BehaviourTreeRunningStatus.EXECUTING);
            }
            bool hasFinished  = false;
            bool hasExecuting = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                if (thisContext.evaluationStatus[i] == false)
                {
                    continue;
                }
                if (BehaviourTreeRunningStatus.IsFinished(thisContext.runningStatus[i]))
                {
                    hasFinished = true;
                    continue;
                }
                BehaviourAction node          = GetChild <BehaviourAction>(i);
                int             runningStatus = node.Update(wData);
                if (BehaviourTreeRunningStatus.IsFinished(runningStatus))
                {
                    hasFinished = true;
                }
                else
                {
                    hasExecuting = true;
                }
                thisContext.runningStatus[i] = runningStatus;
            }
            if (_runningStatusRelationship == ECHILDREN_RELATIONSHIP.OR && hasFinished || _runningStatusRelationship == ECHILDREN_RELATIONSHIP.AND && hasExecuting == false)
            {
                initListTo <int>(thisContext.runningStatus, BehaviourTreeRunningStatus.EXECUTING);
                return(BehaviourTreeRunningStatus.FINISHED);
            }
            return(BehaviourTreeRunningStatus.EXECUTING);
        }
Example #9
0
        protected override int onUpdate(BehaviourTreeData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);
            int runningStatus = BehaviourTreeRunningStatus.FINISHED;

            if (IsIndexValid(0))
            {
                BehaviourAction node = GetChild <BehaviourAction>(0);
                runningStatus = node.Update(wData);
                if (BehaviourTreeRunningStatus.IsFinished(runningStatus))
                {
                    thisContext.currentCount++;
                    if (thisContext.currentCount < _loopCount || _loopCount == INFINITY)
                    {
                        runningStatus = BehaviourTreeRunningStatus.EXECUTING;
                    }
                }
            }
            return(runningStatus);
        }
Example #10
0
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            int checkedNodeIndex = -1;

            if (IsIndexValid(thisContext.currentSelectedIndex))
            {
                checkedNodeIndex = thisContext.currentSelectedIndex;
            }
            else
            {
                checkedNodeIndex = 0;
            }
            if (IsIndexValid(checkedNodeIndex))
            {
                BehaviourAction node = GetChild <BehaviourAction>(checkedNodeIndex);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = checkedNodeIndex;
                    return(true);
                }
            }
            return(false);
        }