Unity3d简易状态机
SimpleFSM 包含状态切换以及事件驱动传递参数
下面的代码是登录的状态码
1 using System; 2 using UnityEngine; 3 using System.Collections; 4 5 public class LoginState : SingletonPrivider<LoginState>, GameState 6 { 7 private delegate void LoginEventHandler(object sender, LoginEventArgs args); 8 private event LoginEventHandler LoginEvent; 9 10 public void Init() 11 { 12 Debug.Log("Init: LoginState"); 13 LoginEvent += UILogin.Instance.GetLoginInfo; 14 Enter(); 15 } 16 17 public void Enter() 18 { 19 Debug.Log("Enter: Login"); 20 LoginEvent(this, new LoginEventArgs("冷雨夜", "123")); 21 } 22 23 public void Exit() 24 { 25 Debug.Log("Exit: LoginState"); 26 LoginEvent -= UILogin.Instance.GetLoginInfo; 27 } 28 29 public GameState Previous() 30 { 31 return null; 32 } 33 34 public GameState Next() 35 { 36 Exit(); 37 GameObject.Destroy(UILogin.Instance.gameObject); 38 LobbyState.Instance.Init(); 39 return LobbyState.Instance; 40 } 41 } 42 43 public class LoginEventArgs : EventArgs 44 { 45 public string username; 46 public string password; 47 48 public LoginEventArgs(string username, string password) 49 { 50 this.username = username; 51 this.password = password; 52 } 53 }
demo在这里
希望给予留言并指正一二