Esempio n. 1
0
        /// <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>();
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
 public void OnEvent(IFsm <FsmDemo> fsm, object sender, int eventId, object userData)
 {
     if (eventId == Event.die)
     {
         fsm.ChangeState <DeadState>();
     }
     else
     {
         Debug.Log("No Response!");
     }
 }
Esempio n. 5
0
    /// <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);
    }
Esempio n. 6
0
    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>();
    }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
 bool OnWork(IFsm <FsmDemo> fsm, object sender, object userData)
 {
     fsm.ChangeState <TiredState>();
     return(true);
 }
Esempio n. 9
0
 bool OnRest(IFsm <FsmDemo> fsm, object sender, object userData)
 {
     fsm.ChangeState <NormalState>();
     return(true);
 }
Esempio n. 10
0
 /// <summary>
 /// 切换当前有限状态机状态。
 /// </summary>
 /// <typeparam name="TState">要切换到的有限状态机状态类型。</typeparam>
 /// <param name="fsm">有限状态机引用。</param>
 protected void ChangeState <TState>(IFsm <T> fsm) where TState : FsmState <T>
 {
     fsm.ChangeState <TState>();
 }
Esempio n. 11
0
 protected void ChangeState(string stateName)
 {
     Fsm.ChangeState(stateName);
 }
Esempio n. 12
0
 /// <summary>
 /// 切换当前有限状态机状态。
 /// </summary>
 /// <param name="stateType">要切换到的有限状态机状态类型。</param>
 public void ChangeState(Type stateType)
 {
     m_ProcedureFsm.ChangeState(stateType);
 }
Esempio n. 13
0
 /// <summary>
 /// 切换当前有限状态机状态。
 /// </summary>
 /// <typeparam name="TState">要切换到的有限状态机状态类型。</typeparam>
 public void ChangeProcedure <TState>()
 {
     fsm.ChangeState(typeof(TState));
 }