Esempio n. 1
0
        protected override int OnUpdate(BTWorkingData wData)
        {
            var thisContext  = (BTCActionPrioritizedSelector *)wData.GetContext(_uniqueKey);
            int runningState = BTRunningStatus.FINISHED;

            if (thisContext->currentSelectedIndex != thisContext->lastSelectedIndex)
            {
                if (IsIndexValid(thisContext->lastSelectedIndex))
                {
                    BTAction node = GetChild <BTAction>(thisContext->lastSelectedIndex);
                    node.Transition(wData);
                }

                thisContext->lastSelectedIndex = thisContext->currentSelectedIndex;
            }

            if (IsIndexValid(thisContext->lastSelectedIndex))
            {
                BTAction node = GetChild <BTAction>(thisContext->lastSelectedIndex);
                runningState = node.Update(wData);
                if (BTRunningStatus.IsFinished(runningState))
                {
                    thisContext->lastSelectedIndex = -1;
                }
            }

            return(runningState);
        }
Esempio n. 2
0
        protected override int OnUpdate(BTWorkingData wData)
        {
            var      thisContext   = (BTCActionSequence *)wData.GetContext(_uniqueKey);
            int      runningStatus = BTRunningStatus.FINISHED;
            BTAction node          = GetChild <BTAction>(thisContext->currentSelectedIndex);

            runningStatus = node.Update(wData);
            if (_continueIfErrorOccors == false && BTRunningStatus.IsError(runningStatus))
            {
                thisContext->currentSelectedIndex = -1;
                return(runningStatus);
            }
            if (BTRunningStatus.IsFinished(runningStatus))
            {
                thisContext->currentSelectedIndex++;
                if (IsIndexValid(thisContext->currentSelectedIndex))
                {
                    runningStatus = BTRunningStatus.EXECUTING;
                }
                else
                {
                    thisContext->currentSelectedIndex = -1;
                }
            }
            return(runningStatus);
        }
        protected override int OnUpdate(BTWorkingData wData)
        {
            var thisContext = (BTCActionParallel *)wData.GetContext(_uniqueKey);
            //first time initialization

            bool hasFinished  = false;
            bool hasExecuting = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                if (thisContext->evaluationStatus[i] == false)
                {
                    continue;
                }

                if (BTRunningStatus.IsFinished(thisContext->StatusRunning[i]))
                {
                    hasFinished = true;
                    continue;
                }

                BTAction node          = GetChild <BTAction>(i);
                int      runningStatus = node.Update(wData);
                if (BTRunningStatus.IsFinished(runningStatus))
                {
                    hasFinished = true;
                }
                else
                {
                    hasExecuting = true;
                }

                thisContext->StatusRunning[i] = (byte)runningStatus;
            }

            if (_runningStatusRelationship == ECHILDREN_RELATIONSHIP.OR && hasFinished ||
                _runningStatusRelationship == ECHILDREN_RELATIONSHIP.AND && hasExecuting == false)
            {
                thisContext->StatusRunning.Init((byte)(int)BTRunningStatus.EXECUTING);
                return(BTRunningStatus.FINISHED);
            }

            return(BTRunningStatus.EXECUTING);
        }
Esempio n. 4
0
        protected override int OnUpdate(BTWorkingData wData)
        {
            var thisContext   = (BTActionLoopContext *)wData.GetContext(_uniqueKey);
            int runningStatus = BTRunningStatus.FINISHED;

            if (IsIndexValid(0))
            {
                BTAction node = GetChild <BTAction>(0);
                runningStatus = node.Update(wData);
                if (BTRunningStatus.IsFinished(runningStatus))
                {
                    thisContext->currentCount++;
                    if (thisContext->currentCount < _loopCount || _loopCount == INFINITY)
                    {
                        runningStatus = BTRunningStatus.EXECUTING;
                    }
                }
            }
            return(runningStatus);
        }