Esempio n. 1
0
        protected override int onUpdate(BehaviourTreeData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);
            int runningState = BehaviourTreeRunningStatus.FINISHED;

            if (thisContext.currentSelectedIndex != thisContext.lastSelectedIndex)
            {
                if (IsIndexValid(thisContext.lastSelectedIndex))
                {
                    BehaviourAction node = GetChild <BehaviourAction>(thisContext.lastSelectedIndex);
                    node.Transition(wData);
                }
                thisContext.lastSelectedIndex = thisContext.currentSelectedIndex;
            }
            if (IsIndexValid(thisContext.lastSelectedIndex))
            {
                BehaviourAction node = GetChild <BehaviourAction>(thisContext.lastSelectedIndex);
                runningState = node.Update(wData);
                if (BehaviourTreeRunningStatus.IsFinished(runningState))
                {
                    thisContext.lastSelectedIndex = -1;
                }
            }
            return(runningState);
        }
Esempio n. 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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }