コード例 #1
0
ファイル: TBTActionSequence.cs プロジェクト: mengtest/Snake-3
        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);
        }
コード例 #2
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);
        }
コード例 #3
0
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

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

            //让所有子节点同时运行
            for (int i = 0; i < GetChildCount(); ++i)
            {
                TBTAction node = GetChild <TBTAction>(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);
        }
コード例 #4
0
ファイル: TBTActionTimer.cs プロジェクト: zwong91/Titan
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: TBTActionSequence.cs プロジェクト: mengtest/Snake-3
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            int checkedNodeIndex = -1;

            if (IsIndexValid(thisContext.currentSelectedIndex))
            {
                checkedNodeIndex = thisContext.currentSelectedIndex;
            }
            else
            {
                checkedNodeIndex = 0;
            }
            // 检测当前节点
            if (IsIndexValid(checkedNodeIndex))
            {
                TBTAction node = GetChild <TBTAction>(checkedNodeIndex);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = checkedNodeIndex;
                    return(true);
                }
            }
            return(false);
        }
コード例 #7
0
ファイル: TBTActionLoop.cs プロジェクト: liuxx220/GameApp
        protected override void onTransition(TBTWorkingData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);

            if (IsIndexValid(0))
            {
                TBTAction node = GetChild <TBTAction>(0);
                node.Transition(wData);
            }
            thisContext.currentCount = 0;
        }
コード例 #8
0
ファイル: TBTActionSequence.cs プロジェクト: mengtest/Snake-3
        protected override void onTransition(TBTWorkingData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            TBTAction node = GetChild <TBTAction>(thisContext.currentSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }
            thisContext.currentSelectedIndex = -1;
        }
コード例 #9
0
ファイル: TBTActionTimer.cs プロジェクト: zwong91/Titan
        protected override void onTransition(TBTWorkingData wData)
        {
            TBTActionTimerContext thisContext = getContext <TBTActionTimerContext>(wData);

            if (IsIndexValid(0))
            {
                TBTAction node = GetChild <TBTAction>(0);
                node.Transition(wData);
            }
            thisContext.lastTime = -1;
        }
コード例 #10
0
        protected override void onTransition(TBTWorkingData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);
            TBTAction node = GetChild <TBTAction>(thisContext.lastSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }
            thisContext.lastSelectedIndex = -1;
        }
コード例 #11
0
        protected override void onTransition(TBTWorkingData wData)
        {
            var thisContext = getContext <TBTActionParallelContext>(wData);

            for (int i = 0; i < GetChildCount(); ++i)
            {
                TBTAction node = GetChild <TBTAction>(i);
                node.Transition(wData);
            }
            //clear running status
            initListTo <int>(thisContext.runningStatus, TBTRunningStatus.EXECUTING);
        }
コード例 #12
0
 protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
 {
     TBTActionPrioritizedSelector.TBTActionPrioritizedSelectorContext thisContext =
         getContext <TBTActionPrioritizedSelector.TBTActionPrioritizedSelectorContext>(wData);
     //check last node first
     if (IsIndexValid(thisContext.currentSelectedIndex))
     {
         TBTAction node = GetChild <TBTAction>(thisContext.currentSelectedIndex);
         if (node.Evaluate(wData))
         {
             return(true);
         }
     }
     return(base.onEvaluate(wData));
 }
コード例 #13
0
ファイル: TBTActionLoop.cs プロジェクト: liuxx220/GameApp
        //-------------------------------------------------------
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);
            bool checkLoopCount = (_loopCount == INFINITY || thisContext.currentCount < _loopCount);

            if (checkLoopCount == false)
            {
                return(false);
            }
            if (IsIndexValid(0))
            {
                TBTAction node = GetChild <TBTAction>(0);
                return(node.Evaluate(wData));
            }
            return(false);
        }
コード例 #14
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);
        }
コード例 #15
0
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);

            thisContext.currentSelectedIndex = -1;
            int childCount = GetChildCount();

            for (int i = 0; i < childCount; ++i)
            {
                TBTAction node = GetChild <TBTAction>(i);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = i;
                    return(true);
                }
            }
            return(false);
        }
コード例 #16
0
ファイル: TBTActionLoop.cs プロジェクト: liuxx220/GameApp
        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);
        }
コード例 #17
0
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);

            thisContext.currentSelectedIndex = -1;
            int childCount = GetChildCount();

            // 按顺序依次判断所有的子节点,只要有一个子节点满足条件就说明处于这个行为树节点,那么这个父节点也就处于这个状态
            // 并设置当前子节点为父节点的当前index
            for (int i = 0; i < childCount; ++i)
            {
                TBTAction node = GetChild <TBTAction>(i);
                if (node.Evaluate(wData))
                {
                    // 只要一个符合,那么就执行这个
                    thisContext.currentSelectedIndex = i;
                    return(true);
                }
            }
            return(false);
        }
コード例 #18
0
ファイル: TBTActionTimer.cs プロジェクト: zwong91/Titan
        //-------------------------------------------------------
        protected override bool onEvaluate(/*in*/ TBTWorkingData wData)
        {
            TBTActionTimerContext thisContext = getContext <TBTActionTimerContext>(wData);

            if (thisContext.lastTime == INFINITY)
            {
                thisContext.lastTime = UnityEngine.Time.time;
            }

            bool checkTimerOver = (UnityEngine.Time.time >= thisContext.lastTime + m_elapseTime);

            if (checkTimerOver == false)
            {
                return(false);
            }
            if (IsIndexValid(0))
            {
                TBTAction node = GetChild <TBTAction>(0);
                return(node.Evaluate(wData));
            }
            return(false);
        }
コード例 #19
0
ファイル: TBTAction.cs プロジェクト: liuxx220/GameApp
 //-------------------------------------------------------------
 public TBTAction(int maxChildCount)
     : base(maxChildCount)
 {
     _uniqueKey = TBTAction.genUniqueKey();
 }
コード例 #20
0
 //-------------------------------------------------------------
 public TBTAction(int maxChildCount)
     : base(maxChildCount)
 {
     // 将GenUniqueKey放在基类是好的,但这个Unique应该作为一个更通用的类
     _uniqueKey = TBTAction.genUniqueKey();
 }