728 lines
26 KiB
C#
728 lines
26 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Gameplay;
|
|
using Gameplay.Net;
|
|
using NLDPB;
|
|
using PhxhSDK;
|
|
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using Button = UnityEngine.UI.Button;
|
|
using Image = UnityEngine.UI.Image;
|
|
using Toggle = UnityEngine.UI.Toggle;
|
|
|
|
public class UI_StartGameInterfaceController : UIWindow
|
|
{
|
|
enum LoginType
|
|
{
|
|
Account,
|
|
PhoneCode
|
|
}
|
|
|
|
#region UI_obj
|
|
//UI GameObj
|
|
///Auto Gen Start///
|
|
public Image Image_Bg;
|
|
public Image Image_BgDark;
|
|
public Button Button_StartGame;
|
|
public Image Image_LoginBg;
|
|
public Button Button_AccountLogin_1;
|
|
//public Image Image_YellowLine_Account_1;
|
|
public Button Button_VerifyCodeLogin_1;
|
|
//public Image Image_YellowLine_VerifyCode_1;
|
|
//public TMP_InputField InputField_Account;
|
|
public Image Image_AccountIcon;
|
|
//public TMP_InputField InputField_Password;
|
|
public Image Image_PasswordIcon;
|
|
//public Toggle Toggle_RememberPassword;
|
|
public TMP_Text Text_RememberPassword;
|
|
public Toggle Toggle_Agreement_1;
|
|
public TMP_Text Text_Agreement_1;
|
|
public Button Button_UnLogin_1;
|
|
public Button Button_Login_1;
|
|
//public TMP_InputField InputField_PhoneNumber;
|
|
public Image Image_PhoneIcon;
|
|
//public TMP_InputField InputField_VerifyCode;
|
|
public Image Image_VerifyCodeIcon;
|
|
public Button Button_GetVerifyCode;
|
|
public Button Button_GetVerifyCodeCooling;
|
|
public Toggle Toggle_Agreement_2;
|
|
public TMP_Text Text_Agreement_2;
|
|
public Button Button_UnLogin_2;
|
|
public Button Button_Login_2;
|
|
public Image Image_UpdateBg;
|
|
public Button Button_Confirm;
|
|
public Button Button_Cancle;
|
|
public Image Image_BottomLine;
|
|
public Button Button_UserCenter;
|
|
public Button Button_Notice;
|
|
public TMP_Text Text_UID;
|
|
public TMP_Text Text_Version;
|
|
public Image Image_DarkSide;
|
|
///Auto Gen End///
|
|
|
|
#endregion
|
|
|
|
#region UI_Class
|
|
class LoginWindow : UIGameObjectWrapper
|
|
{
|
|
public GameObject Root;
|
|
public GameObject VerifyCodeLoginPanel;
|
|
public Toggle Toggle_Agreement;
|
|
|
|
public TMP_InputField InputField_PhoneNumber;
|
|
public TMP_InputField InputField_VerifyCode;
|
|
|
|
public Button Button_GetVerifyCode;
|
|
public Button Button_GetVerifyCodeCooling;
|
|
|
|
public bool isTimer;
|
|
|
|
public Button Button_Login;
|
|
|
|
public LoginWindow(GameObject root,
|
|
UnityAction<String> PhoneNumberEdit,
|
|
UnityAction<String> CodeEdit,
|
|
UnityAction<bool> AgreementAccept,
|
|
UnityAction PhoneCodeLogin,
|
|
UnityAction SendPhoneRequest) : base(root)
|
|
{
|
|
}
|
|
|
|
public virtual void SetLoginType(LoginType loginType)
|
|
{
|
|
}
|
|
|
|
public virtual void CheckLoginButton(LoginType loginType, bool isToggled)
|
|
{
|
|
if (InputField_PhoneNumber.text.Length > 0 && InputField_VerifyCode.text.Length > 0 && isToggled)
|
|
{
|
|
Button_Login.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
Button_Login.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
public void CheckPhoneCodeButton()
|
|
{
|
|
if (InputField_PhoneNumber.text.Length == 11)
|
|
{
|
|
Button_GetVerifyCode.interactable = true;
|
|
}
|
|
else
|
|
{
|
|
Button_GetVerifyCode.interactable = false;
|
|
}
|
|
}
|
|
public async UniTask CoolingTimer()
|
|
{
|
|
int duration = 60;
|
|
isTimer = true;
|
|
|
|
Button_GetVerifyCode.gameObject.SetActive(false);
|
|
Button_GetVerifyCodeCooling.gameObject.SetActive(true);
|
|
while (duration > 0)
|
|
{
|
|
if (!isTimer)
|
|
{
|
|
duration = 0;
|
|
break;
|
|
}
|
|
Button_GetVerifyCodeCooling.GetComponentInChildren<TMP_Text>().text = duration + "s";
|
|
await UniTask.WaitForSeconds(1);
|
|
duration--;
|
|
}
|
|
Button_GetVerifyCode.gameObject.SetActive(true);
|
|
Button_GetVerifyCodeCooling.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 包含账户登录界面
|
|
/// </summary>
|
|
class DebugLoginWindow : LoginWindow
|
|
{
|
|
public Button Button_AccountLogin;
|
|
public Button Button_VerifyCodeLogin;
|
|
|
|
public GameObject AccountLoginPanel;
|
|
public TMP_Dropdown ServerSelecter;
|
|
public Image Image_YellowLine_Account_1;
|
|
public Image Image_YellowLine_VerifyCode_1;
|
|
public Toggle Toggle_RememberPassword;
|
|
|
|
public TMP_InputField InputField_Account;
|
|
public TMP_InputField InputField_Password;
|
|
|
|
public Button Button_Login_Account;
|
|
public Toggle Toggle_Agreement_Account;
|
|
|
|
public DebugLoginWindow(GameObject root, UnityAction<String> PhoneNumberEdit, UnityAction<String> CodeEdit, UnityAction<bool> AgreementAccept, UnityAction PhoneCodeLogin, UnityAction SendPhoneRequest)
|
|
: base(root, PhoneNumberEdit, CodeEdit, AgreementAccept, PhoneCodeLogin, SendPhoneRequest)
|
|
{
|
|
AccountLoginPanel = root.transform.Find("Image_LoginBg/LoginPanel/AccountLogin").gameObject;
|
|
VerifyCodeLoginPanel = root.transform.Find("Image_LoginBg/LoginPanel/VerifyCodeLogin").gameObject;
|
|
ServerSelecter = root.transform.Find("Image_LoginBg/ALDropdown").GetComponent<TMP_Dropdown>();
|
|
Button_AccountLogin = GetComponent<Button>("Image_LoginBg/LoginPanel/Top/AccountLogin/Button_AccountLogin_1");
|
|
Button_VerifyCodeLogin = GetComponent<Button>("Image_LoginBg/LoginPanel/Top/VerifyCodeLogin/Button_VerifyCodeLogin_1");
|
|
Toggle_Agreement = GetComponent<Toggle>("Image_LoginBg/LoginPanel/VerifyCodeLogin/Mid/Info/Agreement/Toggle_Agreement_2");
|
|
Toggle_Agreement_Account = GetComponent<Toggle>("Image_LoginBg/LoginPanel/AccountLogin/Mid/Info/Agreement/Toggle_Agreement_1");
|
|
Image_YellowLine_Account_1 = GetComponent<Image>("Image_LoginBg/LoginPanel/Top/AccountLogin/Button_AccountLogin_1/Image_YellowLine_Account_1");
|
|
Image_YellowLine_VerifyCode_1 = GetComponent<Image>("Image_LoginBg/LoginPanel/Top/VerifyCodeLogin/Button_VerifyCodeLogin_1/Image_YellowLine_VerifyCode_1");
|
|
Toggle_RememberPassword = GetComponent<Toggle>("Image_LoginBg/LoginPanel/AccountLogin/Mid/Info/RememberPassword/Toggle_RememberPassword");
|
|
InputField_Account = GetComponent<TMP_InputField>("Image_LoginBg/LoginPanel/AccountLogin/Mid/Account/InputField_Account");
|
|
InputField_Password = GetComponent<TMP_InputField>("Image_LoginBg/LoginPanel/AccountLogin/Mid/Password/InputField_Password");
|
|
Button_Login_Account = GetComponent<Button>("Image_LoginBg/LoginPanel/AccountLogin/Bottom/Button_Login_1");
|
|
Button_Login = GetComponent<Button>("Image_LoginBg/LoginPanel/VerifyCodeLogin/Bottom/Button_Login_2");
|
|
Button_GetVerifyCode = GetComponent<Button>("Image_LoginBg/LoginPanel/VerifyCodeLogin/Mid/VerifyCode/Button_GetVerifyCode");
|
|
Button_GetVerifyCodeCooling = GetComponent<Button>("Image_LoginBg/LoginPanel/VerifyCodeLogin/Mid/VerifyCode/Button_GetVerifyCodeCooling");
|
|
InputField_PhoneNumber = GetComponent<TMP_InputField>("Image_LoginBg/LoginPanel/VerifyCodeLogin/Mid/Phone/InputField_PhoneNumber");
|
|
InputField_VerifyCode = GetComponent<TMP_InputField>("Image_LoginBg/LoginPanel/VerifyCodeLogin/Mid/VerifyCode/InputField_VerifyCode");
|
|
|
|
InputField_PhoneNumber.onValueChanged.AddListener(PhoneNumberEdit);
|
|
InputField_VerifyCode.onValueChanged.AddListener(CodeEdit);
|
|
Toggle_Agreement.onValueChanged.AddListener(AgreementAccept);
|
|
Toggle_Agreement_Account.onValueChanged.AddListener(AgreementAccept);
|
|
Button_Login.onClick.AddListener(PhoneCodeLogin);
|
|
Button_GetVerifyCode.onClick.AddListener(SendPhoneRequest);
|
|
|
|
ServerSelecter = FindObj("Image_LoginBg/ALDropdown").GetComponent<TMP_Dropdown>();
|
|
ServerSelecter.options.Clear();
|
|
var serverInfo = AppConfig.Instance.GetServerInfo();
|
|
if (serverInfo.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var item in serverInfo)
|
|
{
|
|
ServerSelecter.options.Add(new TMP_Dropdown.OptionData() { text = item.name });
|
|
}
|
|
|
|
var index = PlayerPrefs.GetInt("ServerIndex", 1);
|
|
//serverIndex = index;
|
|
if (index >= 0 && index < serverInfo.Count)
|
|
{
|
|
ServerSelecter.captionText.text = serverInfo[index].name;
|
|
ServerSelecter.value = index;
|
|
}
|
|
else
|
|
{
|
|
ServerSelecter.captionText.text = serverInfo[0].name;
|
|
ServerSelecter.value = 0;
|
|
}
|
|
}
|
|
|
|
public override void SetLoginType(LoginType loginType)
|
|
{
|
|
AccountLoginPanel.SetActive(loginType == LoginType.Account);
|
|
VerifyCodeLoginPanel.SetActive(loginType == LoginType.PhoneCode);
|
|
}
|
|
|
|
public override void CheckLoginButton(LoginType loginType, bool isToggled)
|
|
{
|
|
switch (loginType)
|
|
{
|
|
case LoginType.Account:
|
|
if (InputField_Account.text.Length > 0 && InputField_Password.text.Length > 0 && isToggled)
|
|
{
|
|
Button_Login_Account.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
Button_Login_Account.gameObject.SetActive(false);
|
|
}
|
|
break;
|
|
case LoginType.PhoneCode:
|
|
if (InputField_PhoneNumber.text.Length > 0 && InputField_VerifyCode.text.Length > 0 && isToggled)
|
|
{
|
|
Button_Login.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
Button_Login.gameObject.SetActive(false);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 正式界面,仅支持手机号登录
|
|
/// </summary>
|
|
class ReleaseLoginWindow : LoginWindow
|
|
{
|
|
public Button Button_debug;
|
|
public ReleaseLoginWindow(GameObject root, UnityAction<String> PhoneNumberEdit, UnityAction<String> CodeEdit, UnityAction<bool> AgreementAccept, UnityAction PhoneCodeLogin, UnityAction SendPhoneRequest)
|
|
: base(root, PhoneNumberEdit, CodeEdit, AgreementAccept, PhoneCodeLogin, SendPhoneRequest)
|
|
{
|
|
VerifyCodeLoginPanel = root.transform.Find("Image_Bg/VerifyCodeLogin").gameObject;
|
|
|
|
InputField_PhoneNumber = GetComponent<TMP_InputField>("Image_Bg/VerifyCodeLogin/Mid/Phone/InputField_PhoneNumber");
|
|
InputField_VerifyCode = GetComponent<TMP_InputField>("Image_Bg/VerifyCodeLogin/Mid/VerifyCode/InputField_VerifyCode");
|
|
Button_Login = GetComponent<Button>("Image_Bg/VerifyCodeLogin/Bottom/Button_Login");
|
|
Button_GetVerifyCode = GetComponent<Button>("Image_Bg/VerifyCodeLogin/Mid/VerifyCode/Button_GetVerifyCode");
|
|
Button_GetVerifyCodeCooling = GetComponent<Button>("Image_Bg/VerifyCodeLogin/Mid/VerifyCode/Button_GetVerifyCodeCooling");
|
|
Toggle_Agreement = GetComponent<Toggle>("Image_Bg/VerifyCodeLogin/Mid/Info/Agreement/Toggle_Agreement");
|
|
Button_debug = GetComponent<Button>("Image_Bg/VerifyCodeLogin/Top/AccountLogin/Button_Debug");
|
|
Button_debug.gameObject.SetActive(false);
|
|
|
|
InputField_PhoneNumber.onValueChanged.AddListener(PhoneNumberEdit);
|
|
InputField_VerifyCode.onValueChanged.AddListener(CodeEdit);
|
|
Toggle_Agreement.onValueChanged.AddListener(AgreementAccept);
|
|
Button_Login.onClick.AddListener(PhoneCodeLogin);
|
|
Button_GetVerifyCode.onClick.AddListener(SendPhoneRequest);
|
|
}
|
|
|
|
public override void SetLoginType(LoginType loginType)
|
|
{
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
LoginWindow curShownWindow;
|
|
DebugLoginWindow debugLoginWindow;
|
|
ReleaseLoginWindow releaseLoginWindow;
|
|
|
|
LoginType loginType;
|
|
LoginData loginSaveData;
|
|
/// <summary>
|
|
/// 确认登录后写入数据 (由于切换账号会清空本地数据,在这里做数据缓存)
|
|
/// </summary>
|
|
LoginData tempSaveData;
|
|
bool loginOK = false;
|
|
|
|
int serverIndex = 1;
|
|
|
|
// deal with input data
|
|
public override void PreLoad(object data = null)
|
|
{
|
|
loginSaveData = StorageMgr.Instance.GetStorage<LoginData>("LoginData");
|
|
if (loginSaveData == null)
|
|
loginSaveData = new();
|
|
}
|
|
|
|
// Use this for initialization
|
|
public override void OnInit()
|
|
{
|
|
//bind UI GameObj
|
|
UI_StartGameInterfaceBinder.GetComponents(this);
|
|
|
|
debugLoginWindow = new(FindObj("UI_LoginWindow"), PhoneEdit, PhoneVerifyCodeEdit, OnAgreementAccept, OnPhoneCodeLoginClick, SendPhoneCodeRequest);
|
|
releaseLoginWindow = new(FindObj("UI_LoginWindowNew"), PhoneEdit, PhoneVerifyCodeEdit, OnAgreementAccept, OnPhoneCodeLoginClick, SendPhoneCodeRequest);
|
|
if (Debug.isDebugBuild)
|
|
{
|
|
curShownWindow = releaseLoginWindow;//debugLoginWindow;//
|
|
releaseLoginWindow.Button_debug.gameObject.SetActive(true);
|
|
releaseLoginWindow.Button_debug.onClick.AddListener(() =>
|
|
{
|
|
curShownWindow.IsScaleShow = false;
|
|
curShownWindow = debugLoginWindow;
|
|
curShownWindow.IsScaleShow = true;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
curShownWindow = releaseLoginWindow;
|
|
}
|
|
|
|
curShownWindow.IsScaleShow = true;
|
|
|
|
if (Debug.isDebugBuild)
|
|
{
|
|
var index = PlayerPrefs.GetInt("ServerIndex", 1);
|
|
serverIndex = index;
|
|
AppConfig.Instance.Select(index);
|
|
|
|
debugLoginWindow.ServerSelecter.gameObject.SetActive(true);
|
|
debugLoginWindow.ServerSelecter.onValueChanged.AddListener((int index) =>
|
|
{
|
|
DebugUtil.Log("选择服务器:" + index);
|
|
AppConfig.Instance.Select(index);
|
|
serverIndex = index;
|
|
});
|
|
}
|
|
|
|
BindButton(Button_AccountLogin_1, () => SetLoginType(LoginType.Account));
|
|
BindButton(Button_VerifyCodeLogin_1, () => SetLoginType(LoginType.PhoneCode));
|
|
BindButton(Button_Login_1, OnButtonLogin);
|
|
BindButton(Button_UserCenter, OnCancelCurConnect);
|
|
BindButton(Button_Notice, OnNoticeClick);
|
|
|
|
BindButton(Button_StartGame, OnStartGame);
|
|
|
|
debugLoginWindow.Toggle_RememberPassword.onValueChanged.AddListener(OnRememberPassword);
|
|
debugLoginWindow.InputField_Account.onValueChanged.AddListener(AccountEdit);
|
|
debugLoginWindow.InputField_Password.onValueChanged.AddListener(PasswordEdit);
|
|
|
|
Text_Version.text = "version:" + Application.version;
|
|
Text_UID.gameObject.SetActive(false);
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.LoginComplete, OnLoginOK);
|
|
//EventManager.Instance.Register(Framework.EventManager.EventName.NetError, OnCancelCurConnect);
|
|
EventManager.Instance.Register(EventManager.EventName.PhoneCodeLoginSuc, OnPhoneCodeLoginSuc);
|
|
EventManager.Instance.Register<string>(EventManager.EventName.PhoneCodeLoginFail, OnPhoneCodeLoginFailed);
|
|
EventManager.Instance.Register<string>(EventManager.EventName.PhoneCodeRequsetFail, OnPhoneCodeRequestFailed);
|
|
if (loginSaveData.LoginByPhone)
|
|
{
|
|
SetLoginType(LoginType.PhoneCode);
|
|
}
|
|
else
|
|
{
|
|
SetLoginType(LoginType.Account);
|
|
}
|
|
if (loginSaveData.LoginByAccount && loginSaveData.rememberPassword)
|
|
{
|
|
DebugUtil.Log("已有账号密码,自动登录");
|
|
LoginAction();
|
|
}
|
|
//if (loginSaveData.LoginByPhone)//手机号Token自动登录
|
|
//{
|
|
// PhoneVerifyTool.Instance.RefreshToken = loginSaveData.AuthCode;
|
|
// Actor.Instance.StartLogin(NLDPB.LoginType.Phxhphone, loginSaveData.phoneNumber);
|
|
//}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入账号登录界面
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
void SetLoginType(LoginType type)
|
|
{
|
|
loginType = type;
|
|
|
|
Text_UID.gameObject.SetActive(false);
|
|
Button_StartGame.gameObject.SetActive(false);
|
|
Button_UserCenter.gameObject.SetActive(false);
|
|
Button_Notice.gameObject.SetActive(false);
|
|
|
|
curShownWindow.SetLoginType(loginType);
|
|
curShownWindow.IsScaleShow = true;
|
|
|
|
Image_LoginBg.gameObject.SetActive(true);
|
|
Image_UpdateBg.gameObject.SetActive(false);
|
|
|
|
switch (loginType)
|
|
{
|
|
case LoginType.Account://账号密码登录
|
|
|
|
debugLoginWindow.Image_YellowLine_Account_1.gameObject.SetActive(true);
|
|
debugLoginWindow.Image_YellowLine_VerifyCode_1.gameObject.SetActive(false);
|
|
debugLoginWindow.Toggle_RememberPassword.isOn = loginSaveData.rememberPassword;
|
|
|
|
debugLoginWindow.Toggle_Agreement_Account.isOn = loginSaveData.agreement;
|
|
debugLoginWindow.VerifyCodeLoginPanel.SetActive(false);
|
|
debugLoginWindow.AccountLoginPanel.SetActive(true);
|
|
|
|
if (loginSaveData.account != default)
|
|
{
|
|
debugLoginWindow.InputField_Account.text = loginSaveData.account;
|
|
}
|
|
if (loginSaveData.password != default && loginSaveData.rememberPassword)
|
|
{
|
|
debugLoginWindow.InputField_Password.text = loginSaveData.password;
|
|
}
|
|
else
|
|
{
|
|
debugLoginWindow.InputField_Password.text = string.Empty;
|
|
}
|
|
|
|
break;
|
|
|
|
case LoginType.PhoneCode://手机号验证码登录
|
|
|
|
debugLoginWindow.Image_YellowLine_Account_1.gameObject.SetActive(false);
|
|
debugLoginWindow.Image_YellowLine_VerifyCode_1.gameObject.SetActive(true);
|
|
|
|
debugLoginWindow.Toggle_Agreement.isOn = loginSaveData.agreement;
|
|
|
|
curShownWindow.CheckPhoneCodeButton();
|
|
break;
|
|
|
|
default:
|
|
DebugUtil.LogError("SetLoginType error");
|
|
break;
|
|
}
|
|
|
|
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
|
|
}
|
|
|
|
void HideLoginPanel()
|
|
{
|
|
//Image_LoginBg.gameObject.SetActive(false);
|
|
curShownWindow.IsScaleShow = false;
|
|
|
|
Button_StartGame.gameObject.SetActive(true);
|
|
Button_Notice.gameObject.SetActive(true);
|
|
Button_UserCenter.gameObject.SetActive(true);
|
|
}
|
|
|
|
//invoke when destroy
|
|
public override void OnRelease()
|
|
{
|
|
base.OnRelease();
|
|
EventManager.Instance.Unregister<string>(EventManager.EventName.PhoneCodeLoginFail, OnPhoneCodeLoginFailed);
|
|
EventManager.Instance.Unregister<string>(EventManager.EventName.PhoneCodeRequsetFail, OnPhoneCodeRequestFailed);
|
|
EventManager.Instance.Unregister(EventManager.EventName.PhoneCodeLoginSuc, OnPhoneCodeLoginSuc);
|
|
EventManager.Instance.Unregister(EventManager.EventName.LoginComplete, OnLoginOK);
|
|
//EventManager.Instance.Unregister(Framework.EventManager.EventName.NetError, OnCancelCurConnect);
|
|
}
|
|
|
|
#region Button_Listener
|
|
|
|
void OnRememberPassword(bool isOn)
|
|
{
|
|
loginSaveData.rememberPassword = isOn;
|
|
}
|
|
void OnAgreementAccept(bool isOn)
|
|
{
|
|
loginSaveData.agreement = isOn;
|
|
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
|
|
}
|
|
|
|
void AccountEdit(string text)
|
|
{
|
|
loginSaveData.account = text;
|
|
debugLoginWindow.InputField_Password.text = string.Empty;
|
|
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
|
|
//CheckLoginButton();
|
|
}
|
|
void PasswordEdit(string text)
|
|
{
|
|
loginSaveData.password = text;
|
|
//CheckLoginButton();
|
|
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
|
|
}
|
|
void PhoneEdit(string text)
|
|
{
|
|
loginSaveData.phoneNumber = text;
|
|
//CheckLoginButton();
|
|
curShownWindow.CheckPhoneCodeButton();
|
|
}
|
|
void PhoneVerifyCodeEdit(string text)
|
|
{
|
|
//loginSaveData.verifyCode = text;
|
|
//CheckLoginButton();
|
|
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 尝试登录
|
|
/// </summary>
|
|
void OnButtonLogin()
|
|
{
|
|
if (!loginSaveData.rememberPassword)
|
|
{
|
|
loginSaveData.password = default;
|
|
}
|
|
tempSaveData = new(loginSaveData);//暂存登录数据
|
|
|
|
LoginAction();
|
|
}
|
|
/// <summary>
|
|
/// 请求发送验证码
|
|
/// </summary>
|
|
void SendPhoneCodeRequest()
|
|
{
|
|
PhoneVerifyTool.Instance.PhoneNumber = loginSaveData.phoneNumber;
|
|
PhoneVerifyTool.Instance.PhoneCodeWebRequest();
|
|
|
|
//isTimer = true;
|
|
curShownWindow.CoolingTimer().Forget();
|
|
}
|
|
/// <summary>
|
|
/// 手机验证码登录
|
|
/// </summary>
|
|
void OnPhoneCodeLoginClick()
|
|
{
|
|
tempSaveData = new(loginSaveData);//暂存登录数据
|
|
|
|
PhoneVerifyTool.Instance.PhoneNumber = loginSaveData.phoneNumber;
|
|
PhoneVerifyTool.Instance.HttpVerifyCode = curShownWindow.InputField_VerifyCode.text;
|
|
|
|
Actor.Instance.StartLogin(NLDPB.LoginType.Phxhphone, loginSaveData.phoneNumber);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 服务器登录
|
|
/// </summary>
|
|
void LoginAction()
|
|
{
|
|
#if DEVELOPMENT_BUILD || UNITY_EDITOR
|
|
PlayerPrefs.SetInt("ServerIndex", serverIndex);
|
|
#else
|
|
DebugUtil.Log("尝试登录测试服,在此处修改登录逻辑,连接超时以及登录失败请后续补充");
|
|
var serverInfos = AppConfig.Instance.GetServerInfo();
|
|
AppConfig.Instance.Select(1);
|
|
for (int i = 0; i < serverInfos.Count; i++)
|
|
{
|
|
if (serverInfos[i].name == "测试服1")
|
|
{
|
|
AppConfig.Instance.Select(i);
|
|
DebugUtil.Log("登录测试服");
|
|
break;
|
|
}
|
|
}
|
|
#endif
|
|
Gameplay.Net.Actor.Instance.StartLogin(NLDPB.LoginType.Phxh, loginSaveData.account);
|
|
}
|
|
|
|
void OnLoginOK()
|
|
{
|
|
loginOK = true;
|
|
HideLoginPanel();
|
|
|
|
loginSaveData = StorageMgr.Instance.GetStorage<LoginData>("LoginData");
|
|
if (loginSaveData == null)
|
|
loginSaveData = new();
|
|
|
|
if (tempSaveData != null)
|
|
loginSaveData.SetData(tempSaveData);
|
|
|
|
loginSaveData.LoginByAccount = true;
|
|
StorageMgr.Instance.SyncForce = true;
|
|
|
|
Text_UID.gameObject.SetActive(true);
|
|
Text_UID.text = "UID: " + Actor.Instance.Base.GetProp(ActorProp.ActorId);
|
|
|
|
//return;
|
|
var adultStatus = (int)Actor.Instance.Logic.GetCount((uint)LogicID.AdultAuthStatus);
|
|
if (adultStatus == (int)AAStatus.AasNone)
|
|
{
|
|
DebugUtil.Log("未实名认证");
|
|
//UI_RealNameIdentifyController.Open().Forget();
|
|
UI_NoticeWindowController.Open().Forget();
|
|
}
|
|
}
|
|
|
|
void OnPhoneCodeRequestFailed(string errorMsg)
|
|
{
|
|
CommonUtils.ShowMessageTips(errorMsg);
|
|
//isTimer = false;
|
|
debugLoginWindow.isTimer = false;
|
|
releaseLoginWindow.isTimer = false;
|
|
}
|
|
void OnPhoneCodeLoginSuc()
|
|
{
|
|
if (tempSaveData != null)
|
|
{
|
|
tempSaveData.AccessToken = PhoneVerifyTool.Instance.AccessTokenCode;
|
|
tempSaveData.AuthCode = PhoneVerifyTool.Instance.RefreshToken;//HttpReturnCode;
|
|
tempSaveData.AuthCodeUpdateTime = PhoneVerifyTool.Instance.RefreshTokenTime;
|
|
tempSaveData.ClearAccountLoginData();
|
|
tempSaveData.LoginByPhone = true;
|
|
}
|
|
else
|
|
{
|
|
DebugUtil.LogWarning("暂存登录数据为空!");
|
|
}
|
|
loginSaveData.AuthCode = PhoneVerifyTool.Instance.RefreshToken;//HttpReturnCode;
|
|
loginSaveData.AuthCodeUpdateTime = PhoneVerifyTool.Instance.RefreshTokenTime;
|
|
|
|
DebugUtil.Log("验证码登录成功!保存登录凭证:" + loginSaveData.AuthCode);
|
|
}
|
|
void OnPhoneCodeLoginFailed(string errorMsg)
|
|
{
|
|
CommonUtils.ShowMessageTips(errorMsg);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 用户中心按钮
|
|
/// </summary>
|
|
void OnCancelCurConnect()
|
|
{
|
|
if (loginOK)//TODO 点开用户中心退出原先账号是否需要断开连接
|
|
{
|
|
DebugUtil.Log("登出!断开连接");
|
|
Actor.Instance.OnLogout();
|
|
NetManager.Instance.CloseClient();
|
|
loginOK = false;
|
|
}
|
|
if (loginSaveData.LoginByPhone)
|
|
{
|
|
SetLoginType(LoginType.PhoneCode);
|
|
}
|
|
else
|
|
{
|
|
SetLoginType(LoginType.Account);
|
|
}
|
|
}
|
|
|
|
async void OnNoticeClick()
|
|
{
|
|
await UI_NoticeController.Open();
|
|
}
|
|
|
|
void OnStartGame()
|
|
{
|
|
Actor.Instance.OnEnterGame();
|
|
}
|
|
|
|
#endregion
|
|
|
|
class LoginData
|
|
{
|
|
/// <summary>
|
|
/// 用账号密码成功登录
|
|
/// </summary>
|
|
public bool LoginByAccount = false;
|
|
public string account;
|
|
public string password;
|
|
public bool rememberPassword;
|
|
|
|
/// <summary>
|
|
/// 用手机验证成功登录
|
|
/// </summary>
|
|
public bool LoginByPhone = false;
|
|
public string phoneNumber;
|
|
public string AccessToken;
|
|
public string AuthCode;
|
|
public long AuthCodeUpdateTime;
|
|
|
|
|
|
public bool agreement;
|
|
|
|
public LoginData()
|
|
{
|
|
|
|
}
|
|
public LoginData(LoginData loginData)
|
|
{
|
|
this.LoginByAccount = loginData.LoginByAccount;
|
|
this.LoginByPhone = loginData.LoginByPhone;
|
|
|
|
this.account = loginData.account;
|
|
this.password = loginData.password;
|
|
this.rememberPassword = loginData.rememberPassword;
|
|
this.agreement = loginData.agreement;
|
|
this.phoneNumber = loginData.phoneNumber;
|
|
this.AccessToken = loginData.AccessToken;
|
|
this.AuthCode = loginData.AuthCode;
|
|
this.AuthCodeUpdateTime = loginData.AuthCodeUpdateTime;
|
|
|
|
}
|
|
|
|
public void SetData(LoginData loginData)
|
|
{
|
|
this.LoginByAccount = loginData.LoginByAccount;
|
|
this.LoginByPhone = loginData.LoginByPhone;
|
|
|
|
this.account = loginData.account;
|
|
this.password = loginData.password;
|
|
this.rememberPassword = loginData.rememberPassword;
|
|
this.agreement = loginData.agreement;
|
|
this.phoneNumber = loginData.phoneNumber;
|
|
this.AccessToken = loginData.AccessToken;
|
|
this.AuthCode = loginData.AuthCode;
|
|
this.AuthCodeUpdateTime = loginData.AuthCodeUpdateTime;
|
|
}
|
|
public void ClearAccountLoginData()
|
|
{
|
|
LoginByAccount = false;
|
|
account = string.Empty;
|
|
password = string.Empty;
|
|
rememberPassword = false;
|
|
}
|
|
}
|
|
}
|