public override void Enter(StateMachine obj) { AgentState s = obj.controller.GetState(); GameObject t = obj.FindClosestEnemy(); obj.controller.SetMovementTarget(t.transform); Debug.Log("Enter " + this.GetType().Name + " : " + obj.agent.name + " --> " + obj.controller.GetState().Moving); //obj.agent.animation.CrossFade("walk"); }
void StateMachineInit() { this.sm = new FSM.StateMachine(); this.sm.addState(new PlayerIdle(this)); this.sm.addState(new PlayerRun(this)); this.sm.addState(new PlayerWalk(this)); this.sm.addState(new PlayerRecycle(this)); this.sm.addState(new PlayerShock(this)); this.sm.addState(new PlayerDie(this)); this.sm.SwitchState("idle"); }
public override void Execute(StateMachine obj) { Debug.Log("Execute: " + this.GetType().Name + " Time: " + Time.time); obj.controller.HealNow(); if (obj.environment.enabled) { obj.ChangeState(obj.previousState); } else { obj.ChangeState(DeadState.GetInstance()); } }
public override void Execute(StateMachine obj) { AgentState s = obj.controller.GetState(); // s.AttackTarget = GameObject.Find("AttTarget"); GameObject t = obj.FindClosestEnemy(); float d = Vector3.Distance(obj.agent.transform.position, t.transform.position); Debug.Log(obj.agent.name + ":: " + d+" to "+t.transform.position); if (d > 20) { obj.ChangeState(RoamState.GetInstance()); } }
public override void OnExecute(FSM.StateMachine stateMachine) { float x = Input.GetAxis("Horizontal"); Rigidbody2D rigidbody2D = stateMachine.GetComponent <Rigidbody2D>(); if (x > 0) { // 方向不变 rigidbody2D.transform.eulerAngles = new Vector3(0, 0, 0); } else if (x < 0) { rigidbody2D.transform.eulerAngles = new Vector3(0, 180, 0); } // 移动的基本向量 Vector3 runVector = new Vector3(x, 0, 0); rigidbody2D.transform.position += PlayerVariable.RunVelocity * Time.deltaTime * runVector; }
public override void Execute(StateMachine obj) { GameObject t = obj.FindClosestEnemy(); float d = Vector3.Distance(obj.agent.transform.position, t.transform.position); if (obj.controller.GetState().AttackTarget == null || obj.controller.GetState().CurrentAttackType == -1) { obj.controller.SetAttack(AgentAttack.MEDIUM_RANGE); obj.controller.SetAttackTarget(t); } if (d < obj.controller.GetState().attackTypes[obj.controller.GetState().CurrentAttackType].range/2.0f) { obj.controller.GetState().Moving = false; } else if (d>30) { obj.controller.SetAttackTarget(null); obj.controller.SetAttack(-1); obj.ChangeState(InitialState.GetInstance()); } }
public override void Execute(StateMachine obj) { AgentState s = obj.controller.GetState(); if (s.CurrentPath != null && s.CurrentPath.IsDone()) { obj.controller.GetState().Moving = true; } // s.AttackTarget = GameObject.Find("AttTarget"); GameObject t = obj.FindClosestEnemy(); obj.controller.SetMovementTarget(t.transform); float d = Vector3.Distance(obj.agent.transform.position, t.transform.position); Debug.Log(obj.agent.name + ":: " + d+" to "+t.transform.position); if (d <= 20 ) { int layer = 1 << 9; if (!Physics.Raycast(obj.agent.transform.position, (t.transform.position-obj.agent.transform.position)/d,d,layer)) obj.ChangeState(ChaseState.GetInstance()); } }
public override void OnEnter(FSM.StateMachine stateMachine) { stateMachine.Animator.SetBool(PlayerVariable.IsRun, true); }
public abstract void Exit(StateMachine obj);
public abstract void Execute(StateMachine obj);
public override void Enter(StateMachine obj) { Debug.Log("Enter " + this.GetType().Name); GameObject.Destroy(obj.agent); }
public override void Enter(StateMachine obj) { Debug.Log("Enter " + this.GetType().Name); obj.agent.animation.Play("jump_pose"); }
public override void OnEnter(FSM.StateMachine stateMachine) { // 死亡则禁用状态机 stateMachine.enabled = false; }
public override void Execute(StateMachine obj) { Debug.Log("Execute: " + this.GetType().Name + " Time: " + Time.time); }
public override bool Predicate(FSM.StateMachine stateMachine) { return(Mathf.Abs(Input.GetAxis("Horizontal")) < 0.01f); }
public override void Exit(StateMachine obj) { obj.agent.GetComponent<AgentAI>()._state.Moving = false; }
public override void Enter(StateMachine obj) { Debug.Log("Enter " + this.GetType().Name); obj.agent.animation.CrossFade("run"); }
public abstract void Enter(StateMachine obj);
public override void Exit(StateMachine obj) { Debug.Log("Exit " + this.GetType().Name); }
public override void OnEnter(FSM.StateMachine stateMachine) { // 触发 Idle 动画 stateMachine.Animator.SetBool(PlayerVariable.IsRun, false); }