protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);
            int runningState = TBTRunningStatus.FINISHED;

            // 如果切换节点index了,那么执行转换
            // 那么现在就是上次选择节点和当前节点一致了
            if (thisContext.currentSelectedIndex != thisContext.lastSelectedIndex)
            {
                if (IsIndexValid(thisContext.lastSelectedIndex))
                {
                    TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex);
                    node.Transition(wData);
                }
                thisContext.lastSelectedIndex = thisContext.currentSelectedIndex;
            }
            // 更新当前节点,如果当前节点状态结束,那么设置当前节点为非法
            if (IsIndexValid(thisContext.lastSelectedIndex))
            {
                TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex);
                runningState = node.Update(wData);
                if (TBTRunningStatus.IsFinished(runningState))
                {
                    // 这里应该用Transition
                    thisContext.lastSelectedIndex = -1;
                }
            }
            return(runningState);
        }
Exemplo n.º 2
0
        protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionTimerContext thisContext = getContext <TBTActionTimerContext>(wData);
            int runningStatus = TBTRunningStatus.FINISHED;

            if (IsIndexValid(0))
            {
                TBTAction node = GetChild <TBTAction>(0);
                runningStatus = node.Update(wData);

                if (TBTRunningStatus.IsFinished(runningStatus))
                {
                    if (UnityEngine.Time.time > thisContext.lastTime + m_elapseTime)
                    {
                        runningStatus = TBTRunningStatus.FINISHED;
                    }
                }
                else if (TBTRunningStatus.IsExecuting(runningStatus))
                {
                    if (UnityEngine.Time.time > thisContext.lastTime + m_elapseTime)
                    {
                        thisContext.lastTime = UnityEngine.Time.time;
                    }
                }
            }
            return(runningStatus);
        }
Exemplo n.º 3
0
        protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            int       runningStatus = TBTRunningStatus.FINISHED;
            TBTAction node          = GetChild <TBTAction>(thisContext.currentSelectedIndex);

            // 更新当前节点
            runningStatus = node.Update(wData);

            // 如果当前节点结束或者失败,那么父节点也结束
            if (_continueIfErrorOccors == 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);
        }
Exemplo n.º 4
0
        protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);
            int runningState = TBTRunningStatus.FINISHED;

            if (thisContext.currentSelectedIndex != thisContext.lastSelectedIndex)
            {
                if (IsIndexValid(thisContext.lastSelectedIndex))
                {
                    TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex);
                    node.Transition(wData);
                }
                thisContext.lastSelectedIndex = thisContext.currentSelectedIndex;
            }
            if (IsIndexValid(thisContext.lastSelectedIndex))
            {
                TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex);
                runningState = node.Update(wData);
                if (TBTRunningStatus.IsFinished(runningState))
                {
                    thisContext.lastSelectedIndex = -1;
                }
            }
            return(runningState);
        }
Exemplo n.º 5
0
        protected override int onUpdate(TBTWorkingData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

            //first time initialization
            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);
        }
Exemplo n.º 6
0
        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 (thisContext.currentCount < _loopCount || _loopCount == INFINITY)
                    {
                        runningStatus = TBTRunningStatus.EXECUTING;
                    }
                }
            }
            return(runningStatus);
        }