一、运行流程
开始界面
1. 点击开始游戏按钮,执行 PlayPanel 类 startClick 函数,
1 /// <summary> 2 /// 开始游戏按钮响应函数 3 /// </summary> 4 private void startClick() 5 { 6 Dispatch(AreaCode.UI, UIEvent.START_PANEL_ACTIVE, true); 7 }
该函数向 UI 层发送 START_PANEL_ACTIVE 事件,传输消息 true。
然后是 StartPanel 类 Execute 函数,
1 public override void Execute(int eventCode, object message) 2 { 3 switch (eventCode) 4 { 5 case UIEvent.START_PANEL_ACTIVE: 6 setPanelActive((bool)message); 7 break; 8 default: 9 break; 10 } 11 }
该函数接收消息,调用 setPanelActive 函数显示开始游戏面板。
点击注册账号按钮流程类似。
登录界面:
2. 点击登录按钮,执行 StartPanel 类 loginClick 函数,
1 /// <summary> 2 /// 登录按钮的点击事件处理 3 /// </summary> 4 private void loginClick() 5 { 6 // 若用户名输入为空 7 if (string.IsNullOrEmpty(inputAccount.text)) 8 { 9 promptMsg.Change("用户名输入为空", Color.red); 10 Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg); 11 return; 12 } 13 // 若密码输入为空 14 if (string.IsNullOrEmpty(inputPassword.text)) 15 { 16 promptMsg.Change("密码输入为空", Color.red); 17 Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg); 18 return; 19 } 20 // 若密码输入不是4到16位 21 if(inputPassword.text.Length < 4 22 || inputPassword.text.Length > 16) 23 { 24 promptMsg.Change("密码输入不是4到16位", Color.red); 25 Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg); 26 return; 27 } 28 29 //需要和服务器交互了 30 AccountDto dto = new AccountDto(inputAccount.text, inputPassword.text); 31 socketMsg.Change(OpCode.ACCOUNT, AccountCode.LOGIN, dto); 32 Dispatch(AreaCode.NET, 0, socketMsg); 33 }