Beispiel #1
0
        protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            int runningStatus = TBTRunningStatus.FINISHED;

            if (IsIndexValid(thisContext.currentSelectedIndex))
            {
                TBTAction node = GetChild <TBTAction>(thisContext.currentSelectedIndex);
                runningStatus = node.Update(wData);
                if (_continueIfErrorOccurs == false && TBTRunningStatus.IsError(runningStatus))
                {
                    thisContext.currentSelectedIndex = -1;
                    return(runningStatus);
                }
            }
            if (TBTRunningStatus.IsFinished(runningStatus))
            {
                thisContext.currentSelectedIndex++;
                if (IsIndexValid(thisContext.currentSelectedIndex))
                {
                    runningStatus = TBTRunningStatus.EXECUTING;
                }
                else
                {
                    thisContext.currentSelectedIndex = -1;
                }
            }
            return(runningStatus);
        }
        protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);
            int runningStatus = TBTRunningStatus.FINISHED;

            if (thisContext.lastSelectedIndex != thisContext.currentSelectedIndex)
            {
                if (IsIndexValid(thisContext.lastSelectedIndex))
                {
                    TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex);
                    node.Transition(wData);
                }
                thisContext.lastSelectedIndex = thisContext.currentSelectedIndex;
            }
            if (IsIndexValid(thisContext.currentSelectedIndex))
            {
                TBTAction node = GetChild <TBTAction>(thisContext.currentSelectedIndex);
                runningStatus = node.Update(wData);
                if (TBTRunningStatus.IsFinished(runningStatus))
                {
                    thisContext.lastSelectedIndex = -1;
                }
            }
            return(runningStatus);
        }
        protected sealed override int onUpdate(TBTWorkingData wData)
        {
            int runningStatus = TBTRunningStatus.FINISHED;
            TBTActionLeafContext thisContext = getContext <TBTActionLeafContext>(wData);

            if (thisContext.status == ACTION_READY)
            {
                onEnter(wData);
                thisContext.needExit = true;
                thisContext.status   = ACTION_RUNNING;
            }
            if (thisContext.status == ACTION_RUNNING)
            {
                runningStatus = onExecute(wData);
                if (TBTRunningStatus.IsFinished(runningStatus))
                {
                    thisContext.status = ACTION_FINISHED;
                }
            }
            if (thisContext.status == ACTION_FINISHED)
            {
                if (thisContext.needExit)
                {
                    onExit(wData, runningStatus);
                }
                thisContext.status   = ACTION_READY;
                thisContext.needExit = false;
            }
            return(runningStatus);
        }
Beispiel #4
0
        protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionParellelContext thisContext = getContext <TBTActionParellelContext>(wData);

            if (thisContext.runningStatus.Count != GetChildCount())
            {
                initListTo <int>(thisContext.runningStatus, TBTRunningStatus.EXECUTING);
            }
            bool hasFinished  = false;
            bool hasExecuting = false;

            for (int i = 0; i < GetChildCount(); i++)
            {
                if (thisContext.evaluationStatus[i] == false)
                {
                    continue;
                }
                if (TBTRunningStatus.IsFinished(thisContext.runningStatus[i]))
                {
                    hasFinished = true;
                    continue;
                }

                TBTAction node          = GetChild <TBTAction>(i);
                int       runningStatus = node.Update(wData);
                if (TBTRunningStatus.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, TBTRunningStatus.EXECUTING);
                return(TBTRunningStatus.FINISHED);
            }
            return(TBTRunningStatus.EXECUTING);
        }
        protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);
            int runningStatus = TBTRunningStatus.FINISHED;

            if (IsIndexValid(0))
            {
                TBTAction node = GetChild <TBTAction>(0);
                runningStatus = node.Update(wData);
                if (TBTRunningStatus.IsFinished(runningStatus))
                {
                    thisContext.currentCount++;
                    if (loopCount == INIFITY || thisContext.currentCount < loopCount)
                    {
                        runningStatus = TBTRunningStatus.EXECUTING;
                    }
                }
            }
            return(runningStatus);
        }