private void MsgLoginByTokenRs(Google.Protobuf.IMessage msg) { Proto.LoginByTokenRs protoRs = msg as Proto.LoginByTokenRs; if (protoRs == null) { return; } switch (protoRs.ReturnCode) { case Proto.LoginByTokenRs.Types.ReturnCode.LgrcNotFoundAccount: UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"[No:{protoRs.ReturnCode}]Token与账号不匹配...", Show); break; case Proto.LoginByTokenRs.Types.ReturnCode.LgrcTokenWrong: UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"[No:{protoRs.ReturnCode}]Token不匹配...", Show); break; case Proto.LoginByTokenRs.Types.ReturnCode.LgrcUnkonwn: UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"[No:{protoRs.ReturnCode}]未知错误...", Show); break; case Proto.LoginByTokenRs.Types.ReturnCode.LgrcOk: UiMgr.GetInstance().OpenModalBox0("登录消息", "登录成功,正在进入游戏..."); break; default: UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"[No:{protoRs.ReturnCode}]未知错误...", Show); break; } }
private IEnumerator GetServer() { var globalObj = Global.GetInstance(); UnityWebRequest webRequest = UnityWebRequest.Get($"http://{globalObj.GetServerIp()}:{globalObj.GetServerPort()}/login"); webRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8"); webRequest.downloadHandler = new DownloadHandlerBuffer(); yield return(webRequest.SendWebRequest()); if (webRequest.isHttpError || webRequest.isNetworkError) { UnityEngine.Debug.Log(webRequest.error); UiMgr.GetInstance().OpenModalBox1("登录消息", $"{webRequest.error}", Show); } else { UnityEngine.Debug.Log(webRequest.downloadHandler.text); string result = webRequest.downloadHandler.text; var jsonData = JsonMapper.ToObject <HttpJson>(result); if (jsonData.returncode == 0) { _serverIp = jsonData.ip; _serverPort = jsonData.port; _loginState = UiLoginState.Connect; } else { UnityEngine.Debug.Log(webRequest.error); UiMgr.GetInstance().OpenModalBox1("登录消息", $"获取服务器失败:{jsonData.returncode}", Show); } } }
protected override void OnUpdate() { if (_characterObj == null) { return; } ToUiAccountInfo obj = UiMgr.GetInstance().GetUpdateData <ToUiAccountInfo>(UiUpdateDataType.AccountInfo); if (obj == null) { return; } if (obj.Version == _lastVersion) { return; } _lastVersion = obj.Version; _account = obj.Account; int size = obj.Players.Count; CheckUiComponents(size); for (int i = 0; i < size; i++) { _players[i].Update(obj.Players[i]); } }
protected override void OnUpdate() { var uiMgr = UiMgr.GetInstance(); ToUiAccountInfo obj = uiMgr.GetUpdateData <ToUiAccountInfo>(UiUpdateDataType.AccountInfo); if (obj == null) { return; } if (obj.Version == _lastVersion) { return; } _lastVersion = obj.Version; if (obj.Players.Count == 0) { uiMgr.OpenUi(UiType.RoleCreate); } else { uiMgr.OpenUi(UiType.RoleSelect); } CloseThisUi(); }
protected override void OnUpdate() { if (_loginState == UiLoginState.Connect) { NetworkMgr.GetInstance().Connect(_serverIp, _serverPort, AppType.Login); Hide(); UiMgr.GetInstance().OpenModalBox0("网络连接", $"正在连接服务器..."); _loginState = UiLoginState.Normal; } }
public void Update() { switch (_state) { case ReadyToLoadStateType.Init1: { if (!AssetBundleMgr.GetInstance().IsInited()) { break; } UiMgr.GetInstance().Init(); _state = ReadyToLoadStateType.Init2; break; } case ReadyToLoadStateType.Init2: { if (!UiMgr.GetInstance().IsInited()) { break; } _state = ReadyToLoadStateType.LoadScene; break; } case ReadyToLoadStateType.LoadScene: { // 初始化加载,下面二行可以优化成加载类 GameMain.GetInstance().Init(); // 设置 加载场景需要加载的数据 AsyncLoaderCache cache = AsyncLoaderCache.GetInstance(); cache.Loaders.Clear(); AsyncLoaderScene ssloader = new AsyncLoaderScene(AsyncLoader.SceneLoginAbPath, AsyncLoader.SceneLoginName, AsyncLoader.SceneLoginMapId); cache.Loaders.Add(ssloader); //AsyncLoaderTest testLoader = new AsyncLoaderTest( ); //cache.Loaders.Add( testLoader ); // 准备开始游戏了,加载“加载场景” SceneManager.LoadScene(AsyncLoader.SceneLoader); _state = ReadyToLoadStateType.Ok; break; } case ReadyToLoadStateType.Ok: break; } }
public void Update( ) { if (Input.GetKeyDown(KeyCode.Mouse0)) { if (!UiMgr.GetInstance( ).MouseInGui( )) { m_fDownTime = Time.time; m_downPos = Input.mousePosition; m_mouseState = eGestureState.Down; } else { //GameLogger.GetInstance().Trace( string.Format( "{0} MouseInGUI", Time.realtimeSinceStartup ) ); } } if (Input.GetKeyUp(KeyCode.Mouse0)) { // GameLogger.GetInstance().Trace( string.Format( "{0} m_mouseState:{1}", Time.realtimeSinceStartup, m_mouseState ) ); m_upPos = Input.mousePosition; float distance = Vector3.Distance(m_upPos, m_downPos); switch (m_mouseState) { case eGestureState.Down: { if (distance > 50f) { UpdateSwipeEnd( ); // 滑动判断 } else { float intervalTime = 0.2f; if (Time.time - m_fUpTime < intervalTime && distance < 10f) { UpdateDoubleClick( ); } else { UpdateClick( ); } } } break; } m_fUpTime = Time.time; m_mouseState = eGestureState.Up; } }
private void EventNetworkConnected(AppType appType) { // 发送登录协议 Proto.AccountCheck protoCheck = new Proto.AccountCheck { Account = _inputAccount.text.Trim(), Password = Md5(System.Text.Encoding.Default.GetBytes(_inputPassword.text.Trim())) }; NetworkMgr.GetInstance().SendPacket(Proto.MsgId.C2LAccountCheck, protoCheck); Hide(); UiMgr.GetInstance().OpenModalBox0("登录消息", "正在验证账号..."); }
public UiRoleCreate() : base(UiType.RoleCreate) { _playerCount = 0; var uiMgr = UiMgr.GetInstance(); ToUiAccountInfo obj = uiMgr.GetUpdateData <ToUiAccountInfo>(UiUpdateDataType.AccountInfo); if (obj == null) { return; } _lastVersion = obj.Version; _playerCount = obj.Players.Count; }
private void MsgGameToken(Google.Protobuf.IMessage msg) { Proto.GameToken gameInfo = msg as Proto.GameToken; if (gameInfo == null) { return; } _token = gameInfo.Token; UiMgr.GetInstance().OpenModalBox0("登录消息", "正在连接游戏服务器..."); NetworkMgr.GetInstance().Disconnect(); NetworkMgr.GetInstance().Connect(gameInfo.Ip, gameInfo.Port, AppType.Game); _linkAppType = AppType.Game; }
private void OnClickPlayer() { foreach (var one in _players) { if (!one.IsOn()) { continue; } UiMgr.GetInstance().OpenModalBox0("选择角色", "正在进入地图..."); Proto.SelectPlayer proto = new Proto.SelectPlayer(); proto.PlayerSn = one.PlayerSn; NetworkMgr.GetInstance().SendPacket(Proto.MsgId.C2LSelectPlayer, proto); return; } }
private void MsgAccoutCheckRs(Google.Protobuf.IMessage msg) { Proto.AccountCheckRs protoRs = msg as Proto.AccountCheckRs; if (protoRs == null) { return; } Proto.AccountCheckReturnCode returnCode = protoRs.ReturnCode; UnityEngine.Debug.LogFormat("Recv account check rs. return code:{0}", returnCode); switch (returnCode) { case Proto.AccountCheckReturnCode.ArcOnline: UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"[No:{returnCode}]该账号在线...", Show); break; case Proto.AccountCheckReturnCode.ArcLogging: UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"[No:{returnCode}]该账号正在登录...", Show); break; case Proto.AccountCheckReturnCode.ArcNotFoundAccount: UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"[No:{returnCode}]没有找到账号...", Show); break; case Proto.AccountCheckReturnCode.ArcPasswordWrong: UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"[No:{returnCode}]密码错误...", Show); break; case Proto.AccountCheckReturnCode.ArcOk: UiMgr.GetInstance().OpenModalBox0("登录消息", "登录成功,正在分配游戏服务器..."); break; default: UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"[No:{returnCode}]未知错误...", Show); break; } }
private void EventNetworkDisconnect(AppType appType) { // 只关心 AppType.Login 的网络链接情况 if (appType != AppType.Login) { return; } if (appType != _linkAppType) { return; } UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("网络消息", $"网络断开,请重新登录...", delegate() { UiMgr.GetInstance().CloseAll(); UiMgr.GetInstance().OpenUi(UiType.Login); }); }
private void OnClickCreate( ) { if (string.IsNullOrEmpty(_inputName.text)) { UiMgr.GetInstance( ).OpenModalBox1("创建角色", "角色名不能为空", null); return; } UiMgr.GetInstance( ).OpenModalBox0("创建角色", "角色正在创建中..."); Proto.CreatePlayer proto = new Proto.CreatePlayer( ); proto.Name = _inputName.text; if (_toggleFemale.isOn) { proto.Gender = Proto.Gender.Female; } else { proto.Gender = Proto.Gender.Male; } NetworkMgr.GetInstance( ).SendPacket(Proto.MsgId.C2LCreatePlayer, proto); }
protected override void OnUpdate( ) { var uiMgr = UiMgr.GetInstance(); ToUiAccountInfo obj = uiMgr.GetUpdateData <ToUiAccountInfo>(UiUpdateDataType.AccountInfo); if (obj == null) { return; } if (obj.Version == _lastVersion) { return; } _lastVersion = obj.Version; if (obj.Players.Count > _playerCount) { this.CloseThisUi(); UiMgr.GetInstance().CloseModalBox0(); // 关闭正在显示的“角色正在创建中” uiMgr.OpenUi(UiType.RoleSelect); } }
private void UpdateBeginLoadingBar( ) { _uiLoading = UiMgr.GetInstance( ).OpenUi(UiType.LoadingBar) as UiLoadBar; _phase = AsyncLoaderPhase.LoadingBar; }
private void OnClickCreate() { this.CloseThisUi(); UiMgr.GetInstance().OpenUi(UiType.RoleCreate); }
protected void UpdataUiData(T obj) { _version++; obj.Version = _version; UiMgr.GetInstance( ).UpdateUiData(_uiUpdataType, obj); }
public void CloseThisUi() { Hide(); UiMgr.GetInstance().CloseUi(_uiType, _sn); }
private void EventNetworkDisconnect(AppType appType) { // 不相等的情况,有可能是linkGame之后,收到 login 的 disconnect,此种情况,不需要处理 UiMgr.GetInstance().CloseModalBox0(); UiMgr.GetInstance().OpenModalBox1("登录消息", $"网络断开,请重新登录...", Show); }