/// <summary> /// token登入响应 /// </summary> /// <param name="result"></param> /// <returns></returns> private bool tokenReponse(string result) { if (result == "200") { Dispatch(AreaCode.UI, UIEvent.LOAD_PANEL_ACTIVE, true); Dispatch(AreaCode.UI, UIEvent.LOG_ACTIVE, false); Dispatch(AreaCode.UI, UIEvent.REG_ACTIVE, false); WebData.isLogin = true; } else if (result == "212") { promptMsg.Change(LanguageService.Instance.GetStringByKey("212", String.Empty), Color.white); Dispatch(AreaCode.UI, UIEvent.HINT_ACTIVE, promptMsg); PlayerPrefs.DeleteKey("token"); SceneMsg msg = new SceneMsg("login", () => { Dispatch(AreaCode.UI, UIEvent.LOG_ACTIVE, true); }); Dispatch(AreaCode.SCENE, SceneEvent.MENU_PLAY_SCENE, msg); return(false); } else if (result == "301") { promptMsg.Change(LanguageService.Instance.GetStringByKey("301", String.Empty), Color.white); Dispatch(AreaCode.UI, UIEvent.HINT_ACTIVE, promptMsg); PlayerPrefs.DeleteKey("token"); SceneMsg msg = new SceneMsg("login", () => { Dispatch(AreaCode.UI, UIEvent.LOG_ACTIVE, true); }); Dispatch(AreaCode.SCENE, SceneEvent.MENU_PLAY_SCENE, msg); return(false); } return(false); }
/// <summary> /// 断线重连 /// </summary> public IEnumerator ReConnect() { ReConnectState = true; while (WebData.Instance().RecTimes <= 10) { WebData.Instance().RecTimes += 1; yield return(new WaitForSeconds(5)); if (!WebData.Instance().IsReconnect) { Debug.Log("第" + WebData.Instance().RecTimes + "次重连尝试"); WebData.Instance().OpenWebSocket(); } else { ReConnectState = false; break; } } if (WebData.Instance().RecTimes > 10) { Debug.LogError("网络断开"); //客户端断开网络退出应用 //Application.Quit(); SceneMsg msg = new SceneMsg("login", delegate() { Debug.Log("场景加载完成"); Dispatch(AreaCode.UI, UIEvent.LOG_ACTIVE, true); }); // Dispatch(AreaCode.SCENE, SceneEvent.LOGIN_PLAY_SCENE, msg); } }
/// <summary> /// 返回主菜单按钮被点击 /// </summary> private void OnReMenuClick() { SceneMsg sceneMsg = new SceneMsg(1, "1.mian", () => { SocketMsg socketMsg = new SocketMsg(OpCode.USER, UserSubCode.GET_USER_INFO_CREQ, null); Dispatch(AreaCode.NET, NetEvent.SENDMSG, socketMsg); }); Dispatch(AreaCode.SCENE, SceneEvent.LOAD_SCENE, sceneMsg); }
public override void Execute(int eventCode, object message) { switch (eventCode) { case SceneEvent.MENU_PLAY_SCENE: msg = message as SceneMsg; LoadScene(msg); break; default: break; } }
private void LoadScene(SceneMsg msg) { if (msg.SceneBuildIndex != -1) { SceneManager.LoadScene(msg.SceneBuildIndex); } if (msg.SceneName != null) { SceneManager.LoadScene(msg.SceneName); } if (msg.OnSceneLoaded != null) { OnSceneLoaded = msg.OnSceneLoaded; } }
public override void Execute(int eventCode, object message) { switch (eventCode) { case SceneEvent.LOAD_SCENE: { SceneMsg sceneMsg = message as SceneMsg; LoadScene(sceneMsg); } break; default: break; } }
//private bool initResponse(string msg) //{ // PlayerPrefs.SetString("ClientId", msg); // Debug.LogError("initResponse"+msg); // return true; //} /// <summary> /// 登录响应 /// </summary> private bool loginResponse(string result) { promptMsg.Change(result, Color.red); Dispatch(AreaCode.UI, UIEvent.HINT_ACTIVE, promptMsg); if (result == "登入成功") { //跳转场景 TODO SceneMsg msg = new SceneMsg("menu", delegate() { Debug.Log("场景加载完成"); }); // Dispatch(AreaCode.SCENE, SceneEvent.MENU_PLAY_SCENE, msg); return(true); } return(false); //登录错误 //promptMsg.Change(result.ToString(), Color.red); //Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg); }
/// <summary> /// 登录响应 /// </summary> /// <param name="value"></param> private void Login(string value) { if (value == "账号不存在") { promptMsg.Change("账号不存在", Color.red); Dispatch(AreaCode.UI, UIEvent.PROMPT_PANEL_SHOW, promptMsg); return; } if (value == "账号在线") { promptMsg.Change("账号在线", Color.red); Dispatch(AreaCode.UI, UIEvent.PROMPT_PANEL_SHOW, promptMsg); return; } if (value == "密码错误") { promptMsg.Change("密码错误", Color.red); Dispatch(AreaCode.UI, UIEvent.PROMPT_PANEL_SHOW, promptMsg); return; } if (value == "登录成功") { promptMsg.Change("登录成功", Color.green); Dispatch(AreaCode.UI, UIEvent.PROMPT_PANEL_SHOW, promptMsg); //TODO 跳转场景 SceneMsg sceneMsg = new SceneMsg(1, "1.mian", () => { SocketMsg socketMsg = new SocketMsg(OpCode.USER, UserSubCode.GET_USER_INFO_CREQ, null); Dispatch(AreaCode.NET, NetEvent.SENDMSG, socketMsg); }); Dispatch(AreaCode.SCENE, SceneEvent.LOAD_SCENE, sceneMsg); return; } }
private void Start() { msg = new SceneMsg(); }
private void LoadScene(SceneMsg sceneMsg) { LoadSceneComplete = sceneMsg.LoadComplete; SceneManager.LoadScene(sceneMsg.SceneIndex); }