From 98707ed4a84a7488ad7faf2336c7beecfd2f1095 Mon Sep 17 00:00:00 2001 From: Yuntao Hu <695250295@qq.com> Date: Thu, 15 Aug 2024 12:51:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=B2=89=E8=BF=B7=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Code/Scripts/Framework/Event/Events.cs | 1 + .../Code/Scripts/Gameplay/Net/Actor/Actor.cs | 4 +- .../Gameplay/Net/Actor/Part/PartLogin.cs | 7 +- .../UI/UI_StartGameInterfaceController.cs | 76 +++++++++++++++---- 4 files changed, 72 insertions(+), 16 deletions(-) diff --git a/ProjectNLD/Assets/Code/Scripts/Framework/Event/Events.cs b/ProjectNLD/Assets/Code/Scripts/Framework/Event/Events.cs index dc4e1df1146..ac71e152ff2 100644 --- a/ProjectNLD/Assets/Code/Scripts/Framework/Event/Events.cs +++ b/ProjectNLD/Assets/Code/Scripts/Framework/Event/Events.cs @@ -34,6 +34,7 @@ LevelCharacterArriveBlock, LoginComplete,//当LoginOK时发送消息 + LoginOut,//当登出时发送消息 LevelBattleBegin, LevelComplete, diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Actor.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Actor.cs index e173379ba2c..0ee67b3d420 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Actor.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Actor.cs @@ -102,7 +102,7 @@ namespace Gameplay.Net GameSettingManager.Instance.Init(); } EventManager.Instance.Send(EventManager.EventName.LoginComplete); - + LoginController.Instance.OnLoginOK(); } /// @@ -130,6 +130,8 @@ namespace Gameplay.Net m_Parts[i].OnLogout(); } } + EventManager.Instance.Send(EventManager.EventName.LoginOut); + LoginController.Instance.OnLogout(); } public void StartLogin(NLDPB.LoginType nType, string account) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Part/PartLogin.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Part/PartLogin.cs index 70132830a7d..9c5ab6eb387 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Part/PartLogin.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Part/PartLogin.cs @@ -136,7 +136,12 @@ namespace Gameplay.Net DebugUtil.Log("服务器断开连接!当前处于防沉迷限制"); UI_LongTipController.Open(onClose: () => { - GameClientReconnect.BackToStart(); + var curState = GameStateManager.Instance.GetCurState(); + if (curState is not GameStateStart) + { + GameStateManager.Instance.ChangeState(new GameStateStart()); + } + Actor.Instance.OnLogout(); }).Forget(); return; } diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_StartGameInterfaceController.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_StartGameInterfaceController.cs index b283ce4dad5..58c3042bb3b 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_StartGameInterfaceController.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_StartGameInterfaceController.cs @@ -428,7 +428,7 @@ public class UI_StartGameInterfaceController : UIWindow { SetLoginType(LoginType.Account); } - if (loginSaveData.LoginByAccount && loginSaveData.rememberPassword) + if (loginSaveData.LoginByAccount && loginSaveData.rememberPassword && LoginController.Instance.AutoLogin) { DebugUtil.Log("已有账号密码,自动登录"); LoginAction(); @@ -468,6 +468,7 @@ public class UI_StartGameInterfaceController : UIWindow Text_UID.gameObject.SetActive(false); EventManager.Instance.Register(EventManager.EventName.LoginComplete, OnLoginOK); + EventManager.Instance.Register(EventManager.EventName.LoginOut, OnLogoutComplete); //EventManager.Instance.Register(Framework.EventManager.EventName.NetError, OnCancelCurConnect); EventManager.Instance.Register(EventManager.EventName.PhoneCodeLoginSuc, OnPhoneCodeLoginSuc); EventManager.Instance.Register(EventManager.EventName.PhoneCodeLoginFail, OnPhoneCodeLoginFailed); @@ -476,7 +477,10 @@ public class UI_StartGameInterfaceController : UIWindow //if (loginSaveData.LoginByPhone)//手机号Token自动登录 //{ // PhoneVerifyTool.Instance.RefreshToken = loginSaveData.AuthCode; - // Actor.Instance.StartLogin(NLDPB.LoginType.Phxhphone, loginSaveData.phoneNumber); + // PhoneVerifyTool.Instance.AccessTokenCode = string.Empty; + // PhoneVerifyTool.Instance.RefreshTokenRequest(); + // + // //Actor.Instance.StartLogin(NLDPB.LoginType.Phxhphone, loginSaveData.phoneNumber); //} } @@ -666,7 +670,7 @@ public class UI_StartGameInterfaceController : UIWindow void OnLoginOK() { - loginOK = true; + //loginOK = true; HideLoginPanel(); loginSaveData = StorageMgr.Instance.GetStorage("LoginData"); @@ -691,6 +695,17 @@ public class UI_StartGameInterfaceController : UIWindow UI_NoticeWindowController.Open().Forget(); } } + void OnLogoutComplete() + { + if (loginSaveData.LoginByPhone) + { + SetLoginType(LoginType.PhoneCode); + } + else + { + SetLoginType(LoginType.Account); + } + } void OnPhoneCodeRequestFailed(string errorMsg) { @@ -728,21 +743,21 @@ public class UI_StartGameInterfaceController : UIWindow /// void OnCancelCurConnect() { - if (loginOK)//TODO 点开用户中心退出原先账号是否需要断开连接 + if (LoginController.Instance.IsLogin)//TODO 点开用户中心退出原先账号是否需要断开连接 { DebugUtil.Log("登出!断开连接"); Actor.Instance.OnLogout(); - NetManager.Instance.CloseClient(); - loginOK = false; + //NetManager.Instance.CloseClient(); + //loginOK = false; } - if (loginSaveData.LoginByPhone) - { - SetLoginType(LoginType.PhoneCode); - } - else - { - SetLoginType(LoginType.Account); - } + //if (loginSaveData.LoginByPhone) + //{ + // SetLoginType(LoginType.PhoneCode); + //} + //else + //{ + // SetLoginType(LoginType.Account); + //} } async void OnNoticeClick() @@ -822,3 +837,36 @@ public class UI_StartGameInterfaceController : UIWindow } } } + +public class LoginController : Singlenton +{ + bool autoLogin = true;//第一次尝试自动登录 + public bool AutoLogin + { + get { return autoLogin; } + } + + bool isLogin = false; + public bool IsLogin + { + get { return isLogin; } + } + + public LoginController() + { + autoLogin = true; + isLogin = false; + } + + public void OnLogout() + { + autoLogin = false; + isLogin = false; + } + + public void OnLoginOK() + { + autoLogin = false; + isLogin = true; + } +}