private void MakeFSM() { mFSMSystem = new SoldierFSMSystem(); //参数1:角色的有限状态机 //参数2:控制的对象(为当前角色的对象) SoldierIdleState idleState = new SoldierIdleState(mFSMSystem, this); idleState.AddTransition(SoldierTransition.SeeEnemy, SoldierStateID.Chase); SoldierChaseState chaseState = new SoldierChaseState(mFSMSystem, this); chaseState.AddTransition(SoldierTransition.NoEnemy, SoldierStateID.Idle); chaseState.AddTransition(SoldierTransition.CanAttack, SoldierStateID.Attack); SoldierAttackState attackState = new SoldierAttackState(mFSMSystem, this); attackState.AddTransition(SoldierTransition.NoEnemy, SoldierStateID.Idle); attackState.AddTransition(SoldierTransition.SeeEnemy, SoldierStateID.Chase); mFSMSystem.AddState(idleState, chaseState, attackState); }
public SoldierChaseState(SoldierFSMSystem fsm, ICharacter character) : base(fsm, character) { mStateID = SoldierStateID.Chase; }
public SoldierAttackState(SoldierFSMSystem fsm, ICharacter character) : base(fsm, character) { mStateID = SoldierStateID.Attack; mAttackTimer = mAttackTime; }
public ISoldierState(SoldierFSMSystem fsm, ICharacter character) { mFSM = fsm; mCharacter = character; }