Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

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

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BehaviourAction node = GetChild <BehaviourAction>(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);
        }
Ejemplo n.º 3
0
        protected sealed override int onUpdate(BehaviourTreeData wData)
        {
            int runningState = BehaviourTreeRunningStatus.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)
            {
                runningState = onExecute(wData);
                if (BehaviourTreeRunningStatus.IsFinished(runningState))
                {
                    thisContext.status = ACTION_FINISHED;
                }
            }
            if (thisContext.status == ACTION_FINISHED)
            {
                if (thisContext.needExit)
                {
                    onExit(wData, runningState);
                }
                thisContext.status   = ACTION_READY;
                thisContext.needExit = false;
            }
            return(runningState);
        }
Ejemplo n.º 4
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            BehaviourAction          node        = GetChild <BehaviourAction>(thisContext.currentSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }
            thisContext.currentSelectedIndex = -1;
        }
Ejemplo n.º 5
0
        protected sealed override void onTransition(BehaviourTreeData wData)
        {
            TBTActionLeafContext thisContext = getContext <TBTActionLeafContext>(wData);

            if (thisContext.needExit)
            {
                onExit(wData, BehaviourTreeRunningStatus.TRANSITION);
            }
            thisContext.status   = ACTION_READY;
            thisContext.needExit = false;
        }
Ejemplo n.º 6
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);

            if (IsIndexValid(0))
            {
                BehaviourAction node = GetChild <BehaviourAction>(0);
                node.Transition(wData);
            }
            thisContext.currentCount = 0;
        }
Ejemplo n.º 7
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BehaviourAction node = GetChild <BehaviourAction>(i);
                node.Transition(wData);
            }
            //clear running status
            initListTo <int>(thisContext.runningStatus, BehaviourTreeRunningStatus.EXECUTING);
        }
Ejemplo n.º 8
0
 protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
 {
     BehaviourActionPrioritizedSelector.TBTActionPrioritizedSelectorContext thisContext =
         getContext <BehaviourActionPrioritizedSelector.TBTActionPrioritizedSelectorContext>(wData);
     //check last node first
     if (IsIndexValid(thisContext.currentSelectedIndex))
     {
         BehaviourAction node = GetChild <BehaviourAction>(thisContext.currentSelectedIndex);
         if (node.Evaluate(wData))
         {
             return(true);
         }
     }
     return(base.onEvaluate(wData));
 }
Ejemplo n.º 9
0
        protected T getContext <T>(BehaviourTreeData wData) where T : TBTActionContext, new()
        {
            int uniqueKey = GetHashCode();
            T   thisContext;

            if (wData.context.ContainsKey(uniqueKey) == false)
            {
                thisContext = new T();
                wData.context.Add(uniqueKey, thisContext);
            }
            else
            {
                thisContext = (T)wData.context[uniqueKey];
            }
            return(thisContext);
        }
Ejemplo n.º 10
0
        //-------------------------------------------------------
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);
            bool checkLoopCount = (_loopCount == INFINITY || thisContext.currentCount < _loopCount);

            if (checkLoopCount == false)
            {
                return(false);
            }
            if (IsIndexValid(0))
            {
                BehaviourAction node = GetChild <BehaviourAction>(0);
                return(node.Evaluate(wData));
            }
            return(false);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            int checkedNodeIndex = -1;

            if (IsIndexValid(thisContext.currentSelectedIndex))
            {
                checkedNodeIndex = thisContext.currentSelectedIndex;
            }
            else
            {
                checkedNodeIndex = 0;
            }
            if (IsIndexValid(checkedNodeIndex))
            {
                BehaviourAction node = GetChild <BehaviourAction>(checkedNodeIndex);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = checkedNodeIndex;
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 14
0
 public override bool IsTrue(/*in*/ BehaviourTreeData wData)
 {
     return(GetChild <BehaviourPrecondition>(0).IsTrue(wData) ||
            GetChild <BehaviourPrecondition>(1).IsTrue(wData));
 }
Ejemplo n.º 15
0
 public abstract bool IsTrue(/*in*/ BehaviourTreeData wData);
Ejemplo n.º 16
0
 public override bool IsTrue(/*in*/ BehaviourTreeData wData)
 {
     return(false);
 }
Ejemplo n.º 17
0
 public void Transition(BehaviourTreeData wData)
 {
     onTransition(wData);
 }
Ejemplo n.º 18
0
 protected virtual void onExit(BehaviourTreeData wData, int runningStatus)
 {
 }
Ejemplo n.º 19
0
 //-------------------------------------------------------------
 public bool Evaluate(/*in*/ BehaviourTreeData wData)
 {
     return((_precondition == null || _precondition.IsTrue(wData)) && onEvaluate(wData));
 }
Ejemplo n.º 20
0
 public int Update(BehaviourTreeData wData)
 {
     return(onUpdate(wData));
 }
Ejemplo n.º 21
0
 protected virtual void onTransition(BehaviourTreeData wData)
 {
 }
Ejemplo n.º 22
0
 protected virtual int onUpdate(BehaviourTreeData wData)
 {
     return(BehaviourTreeRunningStatus.FINISHED);
 }
Ejemplo n.º 23
0
 //--------------------------------------------------------
 // inherented by children
 protected virtual bool onEvaluate(/*in*/ BehaviourTreeData wData)
 {
     return(true);
 }
Ejemplo n.º 24
0
 protected T getUserContexData <T>(BehaviourTreeData wData) where T : class, new()
 {
     return(getContext <TBTActionLeafContext>(wData).getUserData <T>());
 }
Ejemplo n.º 25
0
 //--------------------------------------------------------
 // inherented by children-
 protected virtual void onEnter(/*in*/ BehaviourTreeData wData)
 {
 }