public override bool HandlerTrigger(FSMBase fsm) { if (fsm.targetTF == null) { return(false); } return(Vector3.Distance(fsm.transform.position, fsm.targetTF.position) <= fsm.chStates.attackDistance); }
public override void ActionState(FSMBase fsm) { base.ActionState(fsm); if (atkTime <= Time.time) { fsm.skillSystem.UseRandomSkill(); atkTime = Time.time + fsm.chStates.attacklnterval; } }
/// <summary> /// 检测当前状态是否满足 /// </summary> public void Reason(FSMBase fsm) { for (int i = 0; i < Triggers.Count; i++) { if (Triggers[i].HandlerTrigger(fsm)) { //从映射表中获取输出状态 FSMStateID StateID = map[Triggers[i].TriggerID]; //切换状态 fsm.ChangeActiveState(StateID); return; } } }
//--循环 A=B=C=A..... private void LoopPatrolling(FSMBase fsm) { if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) < 0.5f) { // if (index == fsm.wayPoints.Length - 1) // { // // index--; // } // index ++; index = (index + 1) % fsm.wayPoints.Length; } fsm.MoveToTarget(fsm.wayPoints[index].position, 0, fsm.walkSpeed); }
//根据巡逻模式ABC都是数据,应在机里面找 //--往返 A=B=C=B=A..... private void PingPongPatrolling(FSMBase fsm) { if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) < 0.5f) { if (index == fsm.wayPoints.Length - 1) { Array.Reverse(fsm.wayPoints); index++; } index = (index + 1) % fsm.wayPoints.Length; } fsm.MoveToTarget(fsm.wayPoints[index].position, 0, fsm.walkSpeed); }
//--单次 A-B-C private void OncePatrolling(FSMBase fsm) { if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) < 0.5f) { if (index == fsm.wayPoints.Length - 1) { //完成巡逻 fsm.IspatrolComplete = true; return;//退出 } index++; } //fsm.wayPoints[2].position; fsm.MoveToTarget(fsm.wayPoints[index].position, 0, fsm.walkSpeed); }
public override void ActionState(FSMBase fsm) { base.ActionState(fsm); switch (fsm.patrolMode) { case PatrolMode.Once: OncePatrolling(fsm); break; case PatrolMode.Loop: LoopPatrolling(fsm); break; case PatrolMode.PingPong: PingPongPatrolling(fsm); break; } }
public virtual void ExitState(FSMBase fsm) { }
public virtual void ActionState(FSMBase fsm) { }
//为具体状态类提供可选事件 public virtual void EnterState(FSMBase fsm) { }
public override void ExitState(FSMBase fsm) { fsm.StopMove(); base.ExitState(fsm); fsm.anim.SetBool(fsm.chStates.chParams.run, false); }
public override void EnterState(FSMBase fsm) { base.EnterState(fsm); fsm.anim.SetBool(fsm.chStates.chParams.run, true); }
public override void ExitState(FSMBase fsm) { base.ExitState(fsm); fsm.anim.SetBool(fsm.chStates.chParams.Idle, false); }
public override bool HandlerTrigger(FSMBase fsm) { return(fsm.chStates.HP <= 0); }
public override void EnterState(FSMBase fsm) { base.EnterState(fsm); //fsm.anim.SetBool(fsm.chStates.chParams.Death, true); fsm.enabled = false; }
public override bool HandlerTrigger(FSMBase fsm) { return(fsm.targetTF.GetComponent <CharacterStatus>().HP <= 0); }
//逻辑处理 public abstract bool HandlerTrigger(FSMBase fsm);
public override void ActionState(FSMBase fsm) { base.ActionState(fsm); //fsm.targetTF fsm.MoveToTarget(fsm.targetTF.position, fsm.chStates.attackDistance, fsm.runSpeed); }
public override bool HandlerTrigger(FSMBase fsm) { return(fsm.targetTF != null); }
public override bool HandlerTrigger(FSMBase fsm) { return(fsm.IspatrolComplete); }
public override void EnterState(FSMBase fsm) { base.EnterState(fsm); fsm.IspatrolComplete = false; fsm.anim.SetBool(fsm.chStates.chParams.Walk, true); }