// Update is called once per frame void Update() { if (Input.GetKeyUp(KeyCode.Escape)) { if (DialogBase.Actived()) { DebugConsole.Log("Hide"); DialogBase.Hide(); } else { DebugConsole.Log("Show"); DialogBase.Show("ESC", "Are you sure to exit game?", QuitGame); } } if (m_broadcastMsg != "") { // 有系统消息,平移吧 GameObject goBroadcast = GameObject.Find("BroadcastText"); Vector3 pos = goBroadcast.transform.localPosition; pos.x -= 50 * Time.deltaTime; goBroadcast.transform.localPosition = pos; // 从600~-600 if (goBroadcast.transform.localPosition.x < -600) { m_broadcastMsg = ""; } } else { m_broadcastMsg = Lobby.getInstance().GetBroadcast(); if (m_broadcastMsg != "") { GameObject goBroadcast = GameObject.Find("BroadcastText"); goBroadcast.GetComponent <Text>().text = m_broadcastMsg; goBroadcast.transform.localPosition = new Vector3(600, 0, 0); } } if (m_net == null || !m_net.IsRunning()) { // 主动结束了 return; } if (m_net.CheckReconnect()) { CheckLogin(); DialogReconnect.Hide(); } ProtoPacket packet = new ProtoPacket(); if (m_net.RecvTryDequeue(ref packet)) { DebugConsole.Log("Reception handle cmdId:" + packet.cmdId); switch (packet.cmdId) { case Constants.Lion_QuickLoginInfo: { Lobby.getInstance().UserInfo = (LionUserInfo)packet.proto; // 更新LionUser m_login = true; UpdateUserInfoUI(); // 更新大厅主界面中信息 if (packet.callback != null) { packet.callback(); } } break; case Constants.Lion_GetProfile: { LionUserInfo usrInfo = (LionUserInfo)packet.proto; // 更新LionUser if (usrInfo.UserId == Lobby.getInstance().UId) { Lobby.getInstance().UserInfo = usrInfo; } Lobby.getInstance().QueryUserInfo = usrInfo; if (packet.callback != null) { // 通常这里显示个人信息对话框 packet.callback(); } } break; case Constants.Lion_GetTigerStat: { Lobby.getInstance().TigerStatInfo = (TigerStat)packet.proto; if (packet.callback != null) { packet.callback(); } } break; case Constants.Lion_GetFriendRequests: case Constants.Lion_GetFriends: { Lobby.getInstance().FriendIDArray = (LongArray)packet.proto; if (packet.callback != null) { GetFriendSummary(packet.callback); } else { GetFriendSummary(ShowFriendsDlg); } } break; case Constants.Lion_GetFriendSummary: { Lobby.getInstance().CurrentSummaryList = (FriendSummaryList)packet.proto; DebugConsole.Log("Summary count:" + Lobby.getInstance().CurrentSummaryList.Data.Count); if (packet.callback != null) { packet.callback(); } } break; case Constants.Lion_IgnoreFriend: case Constants.Lion_AcceptFriend: case Constants.Lion_AddFriend: case Constants.Lion_DeleteFriend: { Status stat = (Status)packet.proto; if (stat.Code == 0) // successful { if (packet.callback != null) { packet.callback(); } } else { DebugConsole.Log(stat.Desc); } } break; case Constants.Lion_Redirect: { Lobby.getInstance().RedirectInfo = (RedirectResp)packet.proto; // 切换到游戏场景中 //m_net.Close(); DebugConsole.Log("Reception enter slot scene"); Global.NextSceneName = "slot"; SceneManager.LoadScene("loading"); } break; case Constants.Lion_UpdateProfile: { DebugConsole.Log("Lion_UpdateProfile"); Status stat = (Status)packet.proto; if (stat.Code == 0) // successful { if (packet.callback != null) { packet.callback(); } } else { DebugConsole.Log(stat.Desc); } } break; case Constants.Lion_NotifyWeeklyLogin: { // 连续登录奖励 // NotifyWeeklyLogin 返回的intvalue是0-6,0表示今天登陆了(昨天没登录) IntValue iv = (IntValue)packet.proto; DialogDailyBonus.Show(iv.Value); //ExplodeCoin.Show(); } break; case Constants.Lion_TakeLoginBonus: { LongArray la = (LongArray)packet.proto; // la[0] 奖励金币数 // la[1] 最终总数 if (la.Data.Count >= 2) { Lobby.getInstance().UserInfo.Gold = la.Data[1]; // 若有动画,在此添加 JumpAndMoveCoins(6, UpdateUserInfoUI); } } break; case Constants.Lion_NotifyFreeBonus: { // 第一次登陆的时候,数据库里面没有数据,所以返回0 // 后端推送,倒计时剩余时间长度(毫秒),如果小于等于0,直接显示奖励 // 免费奖励 LongValue lv = (LongValue)packet.proto; long curEpoch = (System.DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000; Lobby.getInstance().FreeBonusEpoch = curEpoch + lv.Value; UpdateCountDown(); } break; case Constants.Lion_TakeFreeBonus: { LongArray la = (LongArray)packet.proto; if (la.Data.Count >= 2) { Lobby.getInstance().UserInfo.Gold = la.Data[1]; // 若有动画,在此添加 FlyCoin(Constants.Bonus_Free); UpdateUserInfoUI(); } } break; case Constants.Lion_BuyItem: { Status stat = (Status)packet.proto; // 更新购买相关的:金币 or 背包 DebugConsole.Log("Buy item return:" + stat.Code.ToString()); if (stat.Code == 0) // successful { if (packet.callback != null) { packet.callback(); } } else { DebugConsole.Log(stat.Desc); } } break; case Constants.Lion_Register: { Status stat = (Status)packet.proto; DebugConsole.Log("Register by email return:" + stat.Code.ToString()); if (stat.Code == 0) // successful { if (packet.callback != null) { packet.callback(); } } else { DebugConsole.Log(stat.Desc); DialogBase.Show("Register by email", "Error:" + stat.Desc); } } break; case Constants.Lion_ModPass: { Status stat = (Status)packet.proto; DebugConsole.Log("Modify password return:" + stat.Code.ToString()); if (stat.Code == 0) // successful { if (packet.callback != null) { packet.callback(); } } else { DebugConsole.Log(stat.Desc); DialogBase.Show("Modify password", "Error:" + stat.Desc); } } break; case Constants.Lion_RefreshGold: { LongValue lv = (LongValue)packet.proto; DebugConsole.Log("Refresh gold:" + lv.ToString()); Lobby.getInstance().UserInfo.Gold = lv.Value; UpdateUserInfoUI(); } break; case Constants.Lion_GetShopItems: { Lobby.getInstance().ShopList = (ShopList)packet.proto; DebugConsole.Log("ShopName:" + Lobby.getInstance().ShopList.ShopName); if (packet.callback != null) { packet.callback(); } } break; case Constants.Lion_BroadcastSystemMessage: { Tools.PlayNotification(Constants.Audio.Audio_Notification); StringValue sv = (StringValue)packet.proto; Lobby.getInstance().AddBroadcast(sv.Value); } break; case Constants.Lion_GetItems: { // Lobby.getInstance().UserItemList = (UserItemList)packet.proto; if (packet.callback != null) { packet.callback(); } else { DialogBag.Show(null); } } break; case Constants.Reconnect: { // 展示重连对话框,直到重连成功 if (packet.msgId == 1) { ProtoNet.WriteLog("Reconnecting..."); // 3s后Display中重连 m_net.CheckReconnect(3); DialogReconnect.Show(); } } break; case Constants.Error: { // 展示错误 Status stat = (Status)packet.proto; string err = "Error:" + stat.Code.ToString() + "-" + stat.Desc; DialogBase.Show("ERROR", err); } break; default: { DebugConsole.Log("Reception invalid cmdId:" + packet.cmdId); } break; } } }
// Update is called once per frame void Update() { if (Input.GetKeyUp(KeyCode.Escape)) { //这个地方可以写“再按一次退出”的提示 if (DialogBase.Actived()) { DebugConsole.Log("Hide in Clerk"); DialogBase.Hide(); } else { DebugConsole.Log("Show in Clerk"); DialogBase.Show("ESC", "Exit game?", QuitGame); } //m_escapeTimes++; //StartCoroutine("resetTimes"); //if (m_escapeTimes > 1) //{ // Application.Quit(); //} } if (!m_net.IsRunning()) { return; } if (m_net.CheckReconnect()) { CheckLogin(); } ProtoPacket packet = new ProtoPacket(); if (m_net.RecvTryDequeue(ref packet)) { m_displays.Execute(packet); } GameObject recp = GameObject.Find("Reception"); if (recp == null) { if (m_broadcastMsg != "") { // 有系统消息,平移吧 GameObject goBroadcast = GameObject.Find("BroadcastText"); Vector3 pos = goBroadcast.transform.localPosition; pos.x -= 50 * Time.deltaTime; goBroadcast.transform.localPosition = pos; // 从600~-600 if (goBroadcast.transform.localPosition.x < -600) { m_broadcastMsg = ""; } } else { m_broadcastMsg = Lobby.getInstance().GetBroadcast(); if (m_broadcastMsg != "") { GameObject goBroadcast = GameObject.Find("BroadcastText"); goBroadcast.GetComponent <Text>().text = m_broadcastMsg; goBroadcast.transform.localPosition = new Vector3(600, 0, 0); } } // 不是Lobby,需要处理Reception消息 // 如广播,以及store相关的 ProtoNet net = Reception.Net(); if (net != null) { packet = null; packet = new ProtoPacket(); if (net.RecvTryDequeue(ref packet)) { switch (packet.cmdId) { case Constants.Lion_GetShopItems: { Lobby.getInstance().ShopList = (ShopList)packet.proto; DebugConsole.Log("ShopName:" + Lobby.getInstance().ShopList.ShopName); if (packet.callback != null) { packet.callback(); } } break; case Constants.Lion_BroadcastSystemMessage: { Tools.PlayNotification(Constants.Audio.Audio_Notification); StringValue sv = (StringValue)packet.proto; Lobby.getInstance().AddBroadcast(sv.Value); } break; default: break; } } } } }
// Update is called once per frame void Update() { if (DialogLogin.Actived()) { return; } if (!m_net.IsRunning()) { // 主动结束了 return; } // Step m_net.CheckReconnect(); //if (m_net.CheckReconnect()) //{ //DebugConsole.Log("Door:Reconnect successful."); //CheckLogin(); //DialogBase.Hide(); //} if (m_rcCount > 3) { DialogWarning.Show("No Network!", "Your internet seems to be down.\nPlease check your network settings.", "Retry", "Exit", OnOK, OnCancel, OnOK); return; } ProtoPacket packet = new ProtoPacket(); if (m_net.RecvTryDequeue(ref packet)) { DebugConsole.Log("Door:Reception handle cmdId:" + packet.cmdId); switch (packet.cmdId) { case Constants.Dog_Login: { LoginResp loginResp = (LoginResp)packet.proto; Lobby.getInstance().UId = loginResp.UserId; DebugConsole.Log("UId:" + loginResp.UserId); m_login = true; // 登录成功,重定向 if (packet.callback != null) { // 重定向 packet.callback(); } } break; case Constants.Dog_Redirect: { RedirectResp rdResp = (RedirectResp)packet.proto; Lobby lobby = Lobby.getInstance(); lobby.Domain = rdResp.Domain; lobby.Port = rdResp.Port; lobby.Key = rdResp.Key; m_net.Close(); // 重定向到大厅 DebugConsole.Log("Door:Redirect to lobby:" + lobby.Domain + ":" + lobby.Port); StartCoroutine(LoadingScene()); } break; case Constants.Reconnect: { // 展示重连对话框,直到重连成功 if (packet.msgId == 1) { ProtoNet.WriteLog("Door:Reconnecting..."); // 3s后Display中重连 m_net.CheckReconnect(5); //DialogBase.Show("RECONNECT", "reconnecting"); GameObject.Find("RcText").GetComponent <Text>().text = "Reconnecting..."; m_net.Ip = "182.92.74.240"; m_rcCount++; } else if (packet.msgId == 2) { DebugConsole.Log("Door:Reconnect successful."); //DialogBase.Hide(); GameObject.Find("RcText").GetComponent <Text>().text = "Connect successfully."; // 启动默认登录 if (m_auto) { Login(Redirect); } } } break; case Constants.Error: { // 这里一定是登录错误? Status stat = (Status)packet.proto; string err = "Error:" + stat.Code.ToString() + "-" + stat.Desc; GameObject.Find("RcText").GetComponent <Text>().text = err; // 打开登录对话框 DialogLogin.Show(LoginAsGuest, LoginWithFsID, null); } break; default: { DebugConsole.Log("Door:Invalid cmdId:" + packet.cmdId); } break; } } //process = (int)(async.progress * 100); }