Unity3d簡易狀態機

SimpleFSM 包含狀態切換以及事件驅動傳遞參數ide

下面的代碼是登陸的狀態碼this

 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 }
View Code

demo在這裏spa

但願給予留言並指正一二code

相關文章
相關標籤/搜索