protected override int onExecute(TBTWorkingData wData) { BattleBehaviorWorkingData behaviorData = wData as BattleBehaviorWorkingData; float deltaTime = behaviorData.deltaTime; BattleUnit source = behaviorData.owner; AIBehaviorRequest request = behaviorData.request; Unit target = request.target; Vector2 ownerPos = source.Get2DPosition(); Vector2 targetPos = target.Get2DPosition(); float attackRange = source.GetAttackRange(); float distance = (targetPos - ownerPos).magnitude; if (distance <= attackRange) { return(TBTRunningStatus.FINISHED); } float moveSpeed = source.GetMoveSpeed(); float detalTime = behaviorData.deltaTime; float toForwardX = (targetPos.x - ownerPos.x) / distance; float toForwardZ = (targetPos.y - ownerPos.y) / distance; float newPosX = ownerPos.x + detalTime * moveSpeed * toForwardX; float newPosZ = ownerPos.y + detalTime * moveSpeed * toForwardZ; source.Set2DPosition(newPosX, newPosZ); //BattleLog.Log("【NOD_MoveTo】移动速度:{0} 当前位置:{1},{2} 目标位置:{3},{4} newPosX:{5} newPosZ:{6}}", // moveSpeed.ToString(), ownerPos.x.ToString(),ownerPos.y.ToString(), targetPos.x.ToString(),targetPos.y.ToString() // ,newPosX.ToString(),newPosZ.ToString()); GameMsg.instance.SendMessage(GameMsgDef.Hero_MoveTo, new HeorMoveEventArgs() { id = source.id, targetPos = new Vector3(newPosX, 0, newPosZ), forward = new Vector3(toForwardX, 0, toForwardZ) }); return(TBTRunningStatus.EXECUTING); }
//------------------------------------------------------- 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); }
//------------------------------------------------------ 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); }
//------------------------------------------------------------- /// <summary> /// 评估该节点是否符合准入条件 /// </summary> public bool Evaluate(/*in*/ TBTWorkingData wData) { return((_precondition == null || _precondition.IsTrue(wData)) && onEvaluate(wData)); }
protected virtual void onTransition(TBTWorkingData wData) { }
protected virtual void onExit(TBTWorkingData wData, int runningStatus) { }
//-------------------------------------------------------- // inherented by children- protected virtual void onEnter(/*in*/ TBTWorkingData wData) { }
//-------------------------------------------------------- // inherented by children protected virtual bool onEvaluate(/*in*/ TBTWorkingData wData) { return(true); }
//-------------------------------------------------------- // inherented by children- protected virtual void onEnter(/*in*/ TBTWorkingData wData) { TLogger.PROFILE("Enter Node" + this.ToString()); }
protected virtual void onExit(TBTWorkingData wData, int runningStatus) { TLogger.PROFILE("Exit Node" + this.ToString()); }
public override bool IsTrue(/*in*/ TBTWorkingData wData) { return(GetChild <TBTPrecondition>(0).IsTrue(wData) && GetChild <TBTPrecondition>(1).IsTrue(wData)); }
public override bool IsTrue(/*in*/ TBTWorkingData wData) { return(false); }
public abstract bool IsTrue(/*in*/ TBTWorkingData wData);
public int Update(TBTWorkingData wData) { return(onUpdate(wData)); }
protected virtual int onExecute(TBTWorkingData wData) { TLogger.DEBUG("Excute Node" + this.ToString()); return(TBTRunningStatus.FINISHED); }
public void Transition(TBTWorkingData wData) { onTransition(wData); }
protected T getUserContexData <T>(TBTWorkingData wData) where T : class, new() { return(getContext <TBTActionLeafContext>(wData).getUserData <T>()); }
protected virtual int onUpdate(TBTWorkingData wData) { return(TBTRunningStatus.FINISHED); }
protected override void onExit(TBTWorkingData wData, int runningStatus) { //BattleLog.Log("【NOD_MoveTo】onExit"); }