/// <summary> /// 切换当前有限状态机状态。 /// </summary> /// <typeparam name="TState">要切换到的有限状态机状态类型。</typeparam> /// <param name="fsm">有限状态机引用。</param> public void ChangeState <TState>() where TState : FsmState <T> { if (fsm == null) { throw new Exception("FSM is invalid."); } fsm.ChangeState <TState>(); }
protected void ChangeState <TState>(params object[] param) where TState : FsmState <T> { if (m_Fsm == null) { throw new Exception("FSM is invalid."); } m_Fsm.ChangeState <TState>(param); }
/// <summary> /// 切换当前有限状态机状态。 /// </summary> /// <param name="stateType">要切换到的有限状态机状态类型。</param> public void ChangeState(Type stateType) { Guard.Verify <ArgumentNullException>(fsm == null, "FSM is invalid."); Guard.Verify <ArgumentNullException>(stateType == null, "State type is invalid."); fsm.ChangeState(stateType); }
public void OnEvent(IFsm <FsmDemo> fsm, object sender, int eventId, object userData) { if (eventId == Event.die) { fsm.ChangeState <DeadState>(); } else { Debug.Log("No Response!"); } }
/// <summary> /// 切换当前有限状态机状态。 /// </summary> /// <param name="fsm">有限状态机引用。</param> /// <param name="stateType">要切换到的有限状态机状态类型。</param> protected void ChangeState(IFsm <T> fsm, Type stateType) { if (stateType == null) { throw new Exception("State type is invalid."); } if (!typeof(FsmState <T>).IsAssignableFrom(stateType)) { throw new Exception(string.Format("State type '{0}' is invalid.", stateType.FullName)); } fsm.ChangeState(stateType); }
private void Start() { birthPos = this.transform.position; npcAnimator = this.GetComponent <Animator>(); npcCharacterController = this.GetComponent <CharacterController>(); originalPos = transform.position; defendCollider.OnTriggerEnterEvent += (collider) => { if (collider.transform.tag == "Player") { attackHero = collider.transform; fsm.ChangeState <NPCAttackState>(); } }; defendCollider.OnTriggerExitEvent += (collider) => { if (collider.transform.tag == "Player") { attackHero = null; fsm.ChangeState <NPCDefendState>(); } }; hPComponent = NPCManager.Instance.AddNPCHPUI(this); hPComponent.SetEnable(true); hPComponent.DeadEvent += () => { PlayDeath(); }; fsm = GameEntry.Fsm.CreateFsm(this.GetHashCode().ToString(), this, new NPCDefendState(), new NPCAttackState()); fsm.Start <NPCDefendState>(); }
internal override bool OnEvent(IFsm <FsmTest> fsm, object sender, int eventId, object userData) { if (!base.OnEvent(fsm, sender, eventId, userData)) { if (eventId == Event.die) { fsm.ChangeState <DeadState>(); } else { Framework.Debug.Log("No Response!"); } } return(true); }
bool OnWork(IFsm <FsmDemo> fsm, object sender, object userData) { fsm.ChangeState <TiredState>(); return(true); }
bool OnRest(IFsm <FsmDemo> fsm, object sender, object userData) { fsm.ChangeState <NormalState>(); return(true); }
/// <summary> /// 切换当前有限状态机状态。 /// </summary> /// <typeparam name="TState">要切换到的有限状态机状态类型。</typeparam> /// <param name="fsm">有限状态机引用。</param> protected void ChangeState <TState>(IFsm <T> fsm) where TState : FsmState <T> { fsm.ChangeState <TState>(); }
protected void ChangeState(string stateName) { Fsm.ChangeState(stateName); }
/// <summary> /// 切换当前有限状态机状态。 /// </summary> /// <param name="stateType">要切换到的有限状态机状态类型。</param> public void ChangeState(Type stateType) { m_ProcedureFsm.ChangeState(stateType); }
/// <summary> /// 切换当前有限状态机状态。 /// </summary> /// <typeparam name="TState">要切换到的有限状态机状态类型。</typeparam> public void ChangeProcedure <TState>() { fsm.ChangeState(typeof(TState)); }