// Use this for initialization IEnumerator Start() { mFSM.AddState(IDLE_STATE); mFSM.AddState(RUN_STATE); mFSM.AddState(WALK_STATE); mFSM.AddState(JUMP_STATE); // 白名单方式添加通道 // 待机->跑 mFSM.AddTranslation(IDLE_STATE, RUN_CLICK_EVENT, RUN_STATE, delegate { Debug.LogError("跳转中 IDLE_STATE->RUN_STATE"); }); // 待机->走 mFSM.AddTranslation(IDLE_STATE, WALK_CLICK_EVENT, WALK_STATE, delegate { Debug.LogError("跳转中 IDLE_STATE->WALK_STATE"); }); // 待机->跳 mFSM.AddTranslation(IDLE_STATE, JUMP_CLICK_EVENT, JUMP_STATE, delegate { Debug.LogError("跳转中 IDLE_STATE->JUMP_STATE"); }); mFSM.Start(IDLE_STATE); Debug.LogError("Cur State:" + mFSM.State); yield return(null); }
public void FSMLiteTest_AddTranslation() { string str1 = "work->rest true"; string str2 = "work->rest false"; mFSMLite.AddState("work"); mFSMLite.AddState("rest"); mFSMLite.AddTranslation("work", "work->rest", "rest", delegate { str2 = "work->rest true"; }); mFSMLite.Start("work"); mFSMLite.HandleEvent("work->rest"); Assert.IsNotNull(mFSMLite); Assert.AreEqual(str1, str2); }
void Start() { mPlayerFsm = new QFSMLite(); // 添加状态 mPlayerFsm.AddState(STATE_DIE); mPlayerFsm.AddState(STATE_RUN); mPlayerFsm.AddState(STATE_JUMP); mPlayerFsm.AddState(STATE_DOUBLE_JUMP); mPlayerFsm.AddState(STATE_DIE); // 添加跳转 mPlayerFsm.AddTranslation(STATE_RUN, EVENT_TOUCH_DOWN, STATE_JUMP, JumpThePlayer); mPlayerFsm.AddTranslation(STATE_JUMP, EVENT_TOUCH_DOWN, STATE_DOUBLE_JUMP, DoubleJumpThePlayer); mPlayerFsm.AddTranslation(STATE_JUMP, EVENT_LAND, STATE_RUN, RunThePlayer); mPlayerFsm.AddTranslation(STATE_DOUBLE_JUMP, EVENT_LAND, STATE_RUN, RunThePlayer); // 启动状态机 mPlayerFsm.Start(STATE_RUN); }
// Use this for initialization void Start() { // 注册消息 QEventSystem.Instance.Register(Example5UIEvent.SendEventToExample5UICtrl, ProcessEvent); ResMgr.Instance.InitResMgr(); QUIManager.Instance.SetResolution(1024, 768); QUIManager.Instance.SetMatchOnWidthOrHeight(0); mFSM.AddState(STATE_MAIN_PAGE); mFSM.AddState(STATE_GAME_PAGE); mFSM.AddState(STATE_ABOUT_PAGE); mFSM.AddState(STATE_QUIT_DIALOG); mFSM.AddState(STATE_QUIT); // main->game mFSM.AddTranslation(STATE_MAIN_PAGE, Example5UIEvent.BtnStartClick.ToString(), STATE_GAME_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5MainPage> (); QUIManager.Instance.OpenUI <UIExample5GamePage> (QUILevel.Common); }); // main->about mFSM.AddTranslation(STATE_MAIN_PAGE, Example5UIEvent.BtnAboutClick.ToString(), STATE_ABOUT_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5MainPage> (); QUIManager.Instance.OpenUI <UIExample5AboutPage> (QUILevel.Common); }); // main->quit mFSM.AddTranslation(STATE_MAIN_PAGE, Example5UIEvent.BtnQuitClick.ToString(), STATE_QUIT_DIALOG, delegate { QUIManager.Instance.OpenUI <UIExample5Dialog> (QUILevel.Forward); }); // about->main mFSM.AddTranslation(STATE_ABOUT_PAGE, Example5UIEvent.BtnBackClick.ToString(), STATE_MAIN_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5AboutPage> (); QUIManager.Instance.OpenUI <UIExample5MainPage> (QUILevel.Common); }); // game->main mFSM.AddTranslation(STATE_GAME_PAGE, Example5UIEvent.BtnBackClick.ToString(), STATE_MAIN_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5GamePage> (); QUIManager.Instance.OpenUI <UIExample5MainPage> (QUILevel.Common); }); // quit->quitgame mFSM.AddTranslation(STATE_QUIT_DIALOG, Example5UIEvent.BtnSureClick.ToString(), STATE_QUIT, delegate { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif }); // quit->main mFSM.AddTranslation(STATE_QUIT_DIALOG, Example5UIEvent.BtnCancelClick.ToString(), STATE_MAIN_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5Dialog> (); }); // 设置好当前状态 mFSM.Start(STATE_MAIN_PAGE); QUIManager.Instance.OpenUI <UIExample5MainPage> (QUILevel.Common); }
// Use this for initialization void Start() { // 注册消息 this.RegisterMsgByChannel(QMgrID.UI, Example5UIMsg.SEND_MSG_TO_EXAMPLE_5_UI_CTRL, ProcessEvent); ResMgr.Instance.InitResMgr(); QUIManager.Instance.SetResolution(1024, 768); QUIManager.Instance.SetMatchOnWidthOrHeight(0); mFSM.AddState(STATE_MAIN_PAGE); mFSM.AddState(STATE_GAME_PAGE); mFSM.AddState(STATE_ABOUT_PAGE); mFSM.AddState(STATE_QUIT_DIALOG); mFSM.AddState(STATE_QUIT); // main->game mFSM.AddTranslation(STATE_MAIN_PAGE, Example5UIMsg.BTN_START_CLICK, STATE_GAME_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5MainPage> (); QUIManager.Instance.OpenUI <UIExample5GamePage> (QUILevel.Common, UIPREFAB.BUNDLE_NAME); }); // main->about mFSM.AddTranslation(STATE_MAIN_PAGE, Example5UIMsg.BTN_ABOUT_CLICK, STATE_ABOUT_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5MainPage> (); QUIManager.Instance.OpenUI <UIExample5AboutPage> (QUILevel.Common, UIPREFAB.BUNDLE_NAME); }); // main->quit mFSM.AddTranslation(STATE_MAIN_PAGE, Example5UIMsg.BTN_QUIT_CLICK, STATE_QUIT_DIALOG, delegate { QUIManager.Instance.OpenUI <UIExample5Dialog> (QUILevel.Forward, UIPREFAB.BUNDLE_NAME); }); // about->main mFSM.AddTranslation(STATE_ABOUT_PAGE, Example5UIMsg.BTN_BACK_CLICK, STATE_MAIN_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5AboutPage> (); QUIManager.Instance.OpenUI <UIExample5MainPage> (QUILevel.Common, UIPREFAB.BUNDLE_NAME); }); // game->main mFSM.AddTranslation(STATE_GAME_PAGE, Example5UIMsg.BTN_BACK_CLICK, STATE_MAIN_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5GamePage> (); QUIManager.Instance.OpenUI <UIExample5MainPage> (QUILevel.Common, UIPREFAB.BUNDLE_NAME); }); // quit->quitgame mFSM.AddTranslation(STATE_QUIT_DIALOG, Example5UIMsg.BTN_SURE_CLICK, STATE_QUIT, delegate { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif }); // quit->main mFSM.AddTranslation(STATE_QUIT_DIALOG, Example5UIMsg.BTN_CANCEL_CLICK, STATE_MAIN_PAGE, delegate { QUIManager.Instance.CloseUI <UIExample5Dialog> (); }); // 设置好当前状态 mFSM.Start(STATE_MAIN_PAGE); QUIManager.Instance.OpenUI <UIExample5MainPage> (QUILevel.Common, UIPREFAB.BUNDLE_NAME); }