//------------------------------------------------------ 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); }
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); }
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); }
protected override int onUpdate(BehaviourTreeData wData) { TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData); int runningState = BehaviourTreeRunningStatus.FINISHED; if (thisContext.currentSelectedIndex != thisContext.lastSelectedIndex) { if (IsIndexValid(thisContext.lastSelectedIndex)) { BehaviourAction node = GetChild <BehaviourAction>(thisContext.lastSelectedIndex); node.Transition(wData); } thisContext.lastSelectedIndex = thisContext.currentSelectedIndex; } if (IsIndexValid(thisContext.lastSelectedIndex)) { BehaviourAction node = GetChild <BehaviourAction>(thisContext.lastSelectedIndex); runningState = node.Update(wData); if (BehaviourTreeRunningStatus.IsFinished(runningState)) { thisContext.lastSelectedIndex = -1; } } return(runningState); }
protected override void onTransition(BehaviourTreeData wData) { TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData); BehaviourAction node = GetChild <BehaviourAction>(thisContext.lastSelectedIndex); if (node != null) { node.Transition(wData); } thisContext.lastSelectedIndex = -1; }
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; }
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; }
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; }
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); }
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)); }
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); }
//------------------------------------------------------- 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); }
protected override bool onEvaluate(/*in*/ BehaviourTreeData wData) { TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData); thisContext.currentSelectedIndex = -1; int childCount = GetChildCount(); for (int i = 0; i < childCount; ++i) { BehaviourAction node = GetChild <BehaviourAction>(i); if (node.Evaluate(wData)) { thisContext.currentSelectedIndex = i; return(true); } } return(false); }
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); }
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); }
//------------------------------------------------------ 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); }
public void Transition(BehaviourTreeData wData) { onTransition(wData); }
//------------------------------------------------------------- public bool Evaluate(/*in*/ BehaviourTreeData wData) { return((_precondition == null || _precondition.IsTrue(wData)) && onEvaluate(wData)); }
public int Update(BehaviourTreeData wData) { return(onUpdate(wData)); }
protected virtual int onUpdate(BehaviourTreeData wData) { return(BehaviourTreeRunningStatus.FINISHED); }
protected virtual void onTransition(BehaviourTreeData wData) { }
public abstract bool IsTrue(/*in*/ BehaviourTreeData wData);
public override bool IsTrue(/*in*/ BehaviourTreeData wData) { return(false); }
public override bool IsTrue(/*in*/ BehaviourTreeData wData) { return(GetChild <BehaviourPrecondition>(0).IsTrue(wData) || GetChild <BehaviourPrecondition>(1).IsTrue(wData)); }
//-------------------------------------------------------- // inherented by children- protected virtual void onEnter(/*in*/ BehaviourTreeData wData) { }
protected virtual void onExit(BehaviourTreeData wData, int runningStatus) { }
//-------------------------------------------------------- // inherented by children protected virtual bool onEvaluate(/*in*/ BehaviourTreeData wData) { return(true); }
protected T getUserContexData <T>(BehaviourTreeData wData) where T : class, new() { return(getContext <TBTActionLeafContext>(wData).getUserData <T>()); }