NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_StartGameInterfaceContro...

1056 lines
37 KiB
C#
Raw Normal View History

2024-08-09 13:21:39 +08:00
using Cysharp.Threading.Tasks;
using Framework;
2024-08-09 13:21:39 +08:00
using Gameplay;
2024-07-15 12:20:03 +08:00
using Gameplay.Net;
using NLDPB;
using PhxhSDK;
2024-08-09 13:21:39 +08:00
using System;
2024-08-13 16:11:48 +08:00
using System.Collections.Generic;
2024-08-09 13:21:39 +08:00
using TMPro;
using UnityEngine;
using UnityEngine.Events;
2024-08-13 16:11:48 +08:00
using UnityEngine.Networking;
2024-08-09 13:21:39 +08:00
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
using Toggle = UnityEngine.UI.Toggle;
2024-09-18 17:51:22 +08:00
#if SDK_TAPTAP
using TapSDK.Login;
#endif
public class UI_StartGameInterfaceController : UIWindow
{
2024-07-15 12:20:03 +08:00
enum LoginType
{
Account,
2024-09-13 17:37:36 +08:00
PhoneCode,
TapTap,
2024-11-05 18:45:00 +08:00
Bilibili,
2024-07-15 12:20:03 +08:00
}
#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;
2024-07-15 12:20:03 +08:00
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;
2024-09-09 16:47:18 +08:00
public Button AppleBtn;
2024-09-13 17:37:36 +08:00
/// <summary>
/// TapTap登录按钮
/// </summary>
private Button buttonTapTap;
2024-07-15 12:20:03 +08:00
///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;
2024-08-13 12:30:13 +08:00
public Button Button_GetVerifyCodeCooling;
2024-08-13 16:11:48 +08:00
public TMP_Text Text_Agreement;
2024-08-13 12:30:13 +08:00
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;
}
}
2024-08-13 12:30:13 +08:00
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);
}
2024-08-13 16:11:48 +08:00
protected void SetLinkText(Toggle agreement, TMP_Text text)
2024-08-13 16:11:48 +08:00
{
LinkText linkText = text.GetComponent<LinkText>();
2024-08-13 16:11:48 +08:00
if (linkText == null)
{
DebugUtil.Log("LinkText is null");
}
else
{
2024-10-24 16:45:46 +08:00
string url1= "https://kedrgame.com/user_agreement.txt";
string url2 = "https://kedrgame.com/privacy_agreement.txt";
string url3 = "https://kedrgame.com/children_privacy_agreement.txt";
string content = string.Format("我已详细阅读并同意<link=\"{0}\"><u>《许可服务协议》</u></link> " +
"<link=\"{1}\"><u>《隐私政策》</u></link>" +
"和<link=\"{2}\"><u>《儿童信息及隐私保护政策》</u></link>",
url1, url2, url3);
linkText.SetText(content);
2024-08-13 16:11:48 +08:00
}
linkText.SetOtherAreaClicked(() => agreement.isOn = !agreement.isOn);
2024-08-13 16:11:48 +08:00
}
async void CallAction(string url)
{
var headData = PostHeader.PostHeaderInfo(new Dictionary<string, string>
2024-08-13 17:25:16 +08:00
{
{"timestamp", DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }
});
2024-08-13 16:11:48 +08:00
UnityWebRequest www = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST)
{
downloadHandler = new DownloadHandlerBuffer(),
};
www.SetRequestHeader("signature", headData["signature"]);
www.SetRequestHeader("timestamp", headData["timestamp"]);
try
{
await www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
DebugUtil.LogError(www.downloadHandler.text);
}
else
{
DebugUtil.Log("http消息请求成功\n返回内容" + www.downloadHandler.text);
//WebRequestResult result = JsonConvert.DeserializeObject<WebRequestResult>(www.downloadHandler.text);
//if (result.code == 0)
//{
// //send success msg
// DebugUtil.Log("短信验证码请求成功");
//}
//else
//{
// //send fail msg
// EventManager.Instance.Send(EventManager.EventName.PhoneCodeRequsetFail, "请求失败!" + result.message);
// DebugUtil.LogError("请求失败!" + result.message);
//}
}
}
catch (UnityWebRequestException e)
{
DebugUtil.LogError(e);
EventManager.Instance.Send(EventManager.EventName.PhoneCodeRequsetFail, "请求失败!");
}
}
}
/// <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 TMP_Text Text_Agreement_Account;
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");
2024-08-13 12:30:13 +08:00
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");
2024-08-13 16:11:48 +08:00
Text_Agreement = GetComponent<TMP_Text>("Image_LoginBg/LoginPanel/VerifyCodeLogin/Mid/Info/Agreement/Text_Agreement_2");
Text_Agreement_Account = GetComponent<TMP_Text>("Image_LoginBg/LoginPanel/AccountLogin/Mid/Info/Agreement/Text_Agreement_1");
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);
Button_GetVerifyCode.interactable = false;
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 });
}
2024-10-25 14:44:47 +08:00
var index = PlayerPrefs.GetInt("ServerIndex", 0);
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;
}
base.SetLinkText(Toggle_Agreement, Text_Agreement);
base.SetLinkText(Toggle_Agreement_Account, Text_Agreement_Account);
}
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");
2024-08-13 12:30:13 +08:00
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");
2024-08-13 16:11:48 +08:00
Text_Agreement = GetComponent<TMP_Text>("Image_Bg/VerifyCodeLogin/Mid/Info/Agreement/Text_Agreement");
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);
Button_GetVerifyCode.interactable = false;
base.SetLinkText(Toggle_Agreement, Text_Agreement);
}
public override void SetLoginType(LoginType loginType)
{
}
}
#endregion
LoginWindow curShownWindow;
DebugLoginWindow debugLoginWindow;
ReleaseLoginWindow releaseLoginWindow;
2024-07-15 12:20:03 +08:00
LoginType loginType;
LoginData loginSaveData;
/// <summary>
/// 确认登录后写入数据 (由于切换账号会清空本地数据,在这里做数据缓存)
/// </summary>
LoginData tempSaveData;
bool loginOK = false;
2024-07-15 12:20:03 +08:00
2024-10-25 14:44:47 +08:00
int serverIndex = 0;
2024-07-17 15:29:10 +08:00
// deal with input data
public override void PreLoad(object data = null)
2024-07-15 12:20:03 +08:00
{
loginSaveData = StorageMgr.Instance.GetStorage<LoginData>("LoginData");
if (loginSaveData == null)
loginSaveData = new();
}
public override async UniTask<bool> OnBack(object data = null)
{
await OnBackApp();
return true;
}
// Use this for initialization
public override void OnInit()
{
//bind UI GameObj
UI_StartGameInterfaceBinder.GetComponents(this);
2024-09-13 17:37:36 +08:00
buttonTapTap = GetComponent<Button>("TapTapBtn");
debugLoginWindow = new(FindObj("UI_LoginWindow"), PhoneEdit, PhoneVerifyCodeEdit, OnAgreementAccept, OnPhoneCodeLoginClick, SendPhoneCodeRequest);
releaseLoginWindow = new(FindObj("UI_LoginWindowNew"), PhoneEdit, PhoneVerifyCodeEdit, OnAgreementAccept, OnPhoneCodeLoginClick, SendPhoneCodeRequest);
2024-09-03 17:07:34 +08:00
EventManager.Instance.Register(EventManager.EventName.RealNameVerifyCancel, OnCancelCurConnect);
EventManager.Instance.Register(EventManager.EventName.LoginComplete, OnLoginOK);
EventManager.Instance.Register(EventManager.EventName.LoginOut, OnLogoutComplete);
//EventManager.Instance.Register(EventManager.EventName.NetError, ConnectNetError);
2024-09-03 17:07:34 +08:00
EventManager.Instance.Register(EventManager.EventName.PhoneCodeLoginSuc, OnPhoneCodeLoginSuc);
EventManager.Instance.Register<string>(EventManager.EventName.PhoneCodeLoginFail, OnPhoneCodeLoginFailed);
EventManager.Instance.Register<string>(EventManager.EventName.PhoneCodeRequsetFail, OnPhoneCodeRequestFailed);
2024-08-20 13:51:43 +08:00
#if LOGIN_PHONE//使用手机登录界面
#if DEVELOPMENT_BUILD || DEBUG
curShownWindow = releaseLoginWindow;//debugLoginWindow;//
releaseLoginWindow.Button_debug.gameObject.SetActive(true);
releaseLoginWindow.Button_debug.onClick.AddListener(() =>
2024-08-12 19:39:14 +08:00
{
2024-08-20 13:51:43 +08:00
curShownWindow.IsScaleShow = false;
curShownWindow = debugLoginWindow;
curShownWindow.IsScaleShow = true;
});
#else
curShownWindow = releaseLoginWindow;
#endif
#else
//使用账号登录界面
curShownWindow = debugLoginWindow;
#endif
2024-09-03 17:07:34 +08:00
//curShownWindow.IsScaleShow = true;
HideLoginPanel();
#region 选中服务器
2024-10-15 16:06:43 +08:00
var index = PlayerPrefs.GetInt("ServerIndex", 0);
2024-08-19 15:01:49 +08:00
serverIndex = index;
AppConfig.Instance.Select(index);
2024-08-20 13:51:43 +08:00
#if DEVELOPMENT_BUILD || DEBUG
2024-08-12 19:39:14 +08:00
debugLoginWindow.ServerSelecter.gameObject.SetActive(true);
debugLoginWindow.ServerSelecter.onValueChanged.AddListener((int index) =>
{
DebugUtil.Log("选择服务器:" + index);
AppConfig.Instance.Select(index);
serverIndex = index;
});
2024-08-20 13:51:43 +08:00
#endif
2024-09-18 17:51:22 +08:00
#endregion
2024-09-09 16:47:18 +08:00
#if !UNITY_IOS
AppleBtn.gameObject.SetActive(false);
#endif
BindButton(AppleBtn, AppleLogin);
2024-07-17 15:29:10 +08:00
BindButton(Button_AccountLogin_1, () => SetLoginType(LoginType.Account));
2024-08-19 15:01:49 +08:00
BindButton(Button_VerifyCodeLogin_1, () => SetLoginType(LoginType.PhoneCode));
BindButton(Button_Login_1, OnButtonLogin);
BindButton(Button_UserCenter, ShowLoginPanel);
2024-08-19 15:01:49 +08:00
BindButton(Button_Notice, OnNoticeClick);
2024-09-13 17:37:36 +08:00
BindButton(buttonTapTap, OnTapTapBtnOnClick);
2024-08-19 15:01:49 +08:00
BindButton(Button_StartGame, OnStartGame);
2024-07-15 12:20:03 +08:00
2024-08-19 15:01:49 +08:00
debugLoginWindow.Toggle_RememberPassword.onValueChanged.AddListener(OnRememberPassword);
debugLoginWindow.InputField_Account.onValueChanged.AddListener(AccountEdit);
debugLoginWindow.InputField_Password.onValueChanged.AddListener(PasswordEdit);
2024-07-15 12:20:03 +08:00
Text_Version.text = "version:" + Application.version;
2024-08-19 15:01:49 +08:00
Text_UID.gameObject.SetActive(false);
2024-07-15 12:20:03 +08:00
//if (loginSaveData.LoginByPhone)//手机号Token自动登录
//{
// PhoneVerifyTool.Instance.RefreshToken = loginSaveData.AuthCode;
2024-08-15 12:51:51 +08:00
// PhoneVerifyTool.Instance.AccessTokenCode = string.Empty;
// PhoneVerifyTool.Instance.RefreshTokenRequest();
//
// //Actor.Instance.StartLogin(NLDPB.LoginType.Phxhphone, loginSaveData.phoneNumber);
//}
}
2024-09-09 16:47:18 +08:00
private void AppleLogin()
2024-11-13 14:29:02 +08:00
{
Actor.Instance.StartLogin(NLDPB.LoginType.Apple, "");
2024-09-09 16:47:18 +08:00
}
2024-07-15 12:20:03 +08:00
/// <summary>
2024-07-16 15:24:41 +08:00
/// 进入账号登录界面
2024-07-15 12:20:03 +08:00
/// </summary>
/// <param name="type"></param>
void SetLoginType(LoginType type)
{
loginType = type;
2024-07-16 13:11:18 +08:00
Text_UID.gameObject.SetActive(false);
Button_StartGame.gameObject.SetActive(false);
Button_UserCenter.gameObject.SetActive(false);
Button_Notice.gameObject.SetActive(false);
curShownWindow.SetLoginType(loginType);
2024-08-09 13:21:39 +08:00
curShownWindow.IsScaleShow = true;
Image_LoginBg.gameObject.SetActive(true);
Image_UpdateBg.gameObject.SetActive(false);
2024-07-15 12:20:03 +08:00
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;
2024-07-15 12:20:03 +08:00
debugLoginWindow.Toggle_Agreement_Account.isOn = loginSaveData.agreement;
debugLoginWindow.VerifyCodeLoginPanel.SetActive(false);
debugLoginWindow.AccountLoginPanel.SetActive(true);
2024-07-15 12:20:03 +08:00
if (loginSaveData.account != default)
{
debugLoginWindow.InputField_Account.text = loginSaveData.account;
2024-07-15 12:20:03 +08:00
}
if (loginSaveData.password != default && loginSaveData.rememberPassword)
{
debugLoginWindow.InputField_Password.text = loginSaveData.password;
}
else
{
debugLoginWindow.InputField_Password.text = string.Empty;
2024-07-15 12:20:03 +08:00
}
break;
case LoginType.PhoneCode://手机号验证码登录
2024-07-15 12:20:03 +08:00
debugLoginWindow.Image_YellowLine_Account_1.gameObject.SetActive(false);
debugLoginWindow.Image_YellowLine_VerifyCode_1.gameObject.SetActive(true);
2024-07-15 12:20:03 +08:00
debugLoginWindow.Toggle_Agreement.isOn = loginSaveData.agreement;
2024-07-15 12:20:03 +08:00
curShownWindow.CheckPhoneCodeButton();
2024-07-15 12:20:03 +08:00
break;
2024-09-13 17:37:36 +08:00
case LoginType.TapTap:
{
curShownWindow.IsScaleShow = false;
buttonTapTap.gameObject.IsScaleShow(true);
}
break;
2024-11-06 18:27:02 +08:00
2024-11-05 18:45:00 +08:00
case LoginType.Bilibili:
{
curShownWindow.IsScaleShow = false;
buttonTapTap.gameObject.IsScaleShow(false);
#if SDK_BILIBILI
2024-11-08 14:11:48 +08:00
Debug.Log("登录bilibili");
GSCSdkInterface.login();
2024-11-05 18:45:00 +08:00
//TapTapLogin.Instance.Logout();
//Actor.Instance.StartLogin(NLDPB.LoginType.b, "");
#endif
}
break;
default:
DebugUtil.LogError("SetLoginType error");
2024-07-15 12:20:03 +08:00
break;
}
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
2024-07-15 12:20:03 +08:00
}
void HideLoginPanel()
2024-09-13 17:37:36 +08:00
{
//Image_LoginBg.gameObject.SetActive(false);
curShownWindow.IsScaleShow = false;
2024-09-13 17:37:36 +08:00
buttonTapTap.gameObject.IsScaleShow(false);
2024-07-16 13:11:18 +08:00
Button_StartGame.gameObject.SetActive(true);
Button_Notice.gameObject.SetActive(true);
2024-09-13 17:37:36 +08:00
Button_UserCenter.gameObject.SetActive(true);
2024-07-15 12:20:03 +08:00
}
2024-09-13 17:37:36 +08:00
//invoke when destroy
public override void OnRelease()
{
base.OnRelease();
2024-09-23 16:00:11 +08:00
debugLoginWindow.isTimer = false;
releaseLoginWindow.isTimer = false;
EventManager.Instance.Unregister(EventManager.EventName.RealNameVerifyCancel, OnCancelCurConnect);
2024-08-07 15:45:10 +08:00
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(EventManager.EventName.LoginOut, OnLogoutComplete);
//EventManager.Instance.Unregister(EventManager.EventName.NetError, ConnectNetError);
//EventManager.Instance.Unregister(Framework.EventManager.EventName.NetError, OnCancelCurConnect);
}
2024-07-15 12:20:03 +08:00
#region Button_Listener
2024-07-15 12:20:03 +08:00
void OnRememberPassword(bool isOn)
{
loginSaveData.rememberPassword = isOn;
}
void OnAgreementAccept(bool isOn)
{
loginSaveData.agreement = isOn;
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
}
2024-07-15 12:20:03 +08:00
void AccountEdit(string text)
2024-07-15 12:20:03 +08:00
{
loginSaveData.account = text;
debugLoginWindow.InputField_Password.text = string.Empty;
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
//CheckLoginButton();
2024-07-15 12:20:03 +08:00
}
void PasswordEdit(string text)
2024-07-15 12:20:03 +08:00
{
loginSaveData.password = text;
//CheckLoginButton();
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
2024-07-15 12:20:03 +08:00
}
2024-07-30 19:07:27 +08:00
void PhoneEdit(string text)
{
loginSaveData.phoneNumber = text;
//CheckLoginButton();
curShownWindow.CheckPhoneCodeButton();
2024-07-30 19:07:27 +08:00
}
void PhoneVerifyCodeEdit(string text)
{
//loginSaveData.verifyCode = text;
//CheckLoginButton();
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
2024-07-30 19:07:27 +08:00
}
2024-07-15 12:20:03 +08:00
/// <summary>
2024-07-16 15:24:41 +08:00
/// 尝试登录
/// </summary>
2024-07-15 12:20:03 +08:00
void OnButtonLogin()
{
if (!loginSaveData.rememberPassword)
{
loginSaveData.password = default;
}
2024-09-10 11:41:36 +08:00
loginSaveData.LoginByAccount = true;
2024-07-16 15:24:41 +08:00
tempSaveData = new(loginSaveData);//暂存登录数据
2024-07-15 12:20:03 +08:00
LoginAction();
2024-09-26 19:16:39 +08:00
BIManager.Instance.TrackEvent("login_check", new Dictionary<string, object>
{
{"method",0 }//0表示手动输入登录
});
2024-09-03 19:17:08 +08:00
DebugUtil.Log("点击登录按钮,拉起加载图标遮挡");
2024-07-15 12:20:03 +08:00
}
2024-09-18 17:51:22 +08:00
2024-07-30 19:07:27 +08:00
/// <summary>
/// 请求发送验证码
/// </summary>
void SendPhoneCodeRequest()
{
curShownWindow.CoolingTimer().Forget();
2024-08-07 15:45:10 +08:00
PhoneVerifyTool.Instance.PhoneNumber = loginSaveData.phoneNumber;
PhoneVerifyTool.Instance.PhoneCodeWebRequest();
2024-08-13 12:30:13 +08:00
//isTimer = true;
2024-07-30 19:07:27 +08:00
}
2024-09-18 17:51:22 +08:00
2024-07-30 19:07:27 +08:00
/// <summary>
/// 手机验证码登录
/// </summary>
2024-08-07 15:45:10 +08:00
void OnPhoneCodeLoginClick()
2024-07-30 19:07:27 +08:00
{
tempSaveData = new(loginSaveData);//暂存登录数据
2024-08-07 15:45:10 +08:00
PhoneVerifyTool.Instance.PhoneNumber = loginSaveData.phoneNumber;
PhoneVerifyTool.Instance.HttpVerifyCode = curShownWindow.InputField_VerifyCode.text;
2024-08-07 15:45:10 +08:00
#if DEVELOPMENT_BUILD || DEBUG
PlayerPrefs.SetInt("ServerIndex", serverIndex);
#else
var serverInfos = AppConfig.Instance.GetServerInfo();
AppConfig.Instance.Select(serverIndex);
#endif
2024-09-26 19:16:39 +08:00
BIManager.Instance.TrackEvent("login_check", new Dictionary<string, object>
{
{"method",0 }//0表示手动输入登录
});
2024-08-07 15:45:10 +08:00
Actor.Instance.StartLogin(NLDPB.LoginType.Phxhphone, loginSaveData.phoneNumber);
2024-10-14 18:32:25 +08:00
DebugUtil.Log("点击登录按钮,拉起加载图标遮挡");
2024-07-30 19:07:27 +08:00
}
2024-09-13 17:37:36 +08:00
/// <summary>
/// TapTap登录
/// </summary>
private void OnTapTapBtnOnClick()
{
2024-09-25 16:39:30 +08:00
#if SDK_TAPTAP
WaitingForServer.Instance.EventWaiting(WaitingForServer.EventName.TapTapLogin, false, false);
2024-09-25 16:39:30 +08:00
TapTapLogin.Instance.Logout();
2024-09-13 17:37:36 +08:00
Actor.Instance.StartLogin(NLDPB.LoginType.TapTap, "");
2024-09-25 16:39:30 +08:00
#endif
2024-09-13 17:37:36 +08:00
}
2024-08-19 15:01:49 +08:00
/// <summary>
/// 服务器登录
/// </summary>
void LoginAction()
{
2024-08-20 13:51:43 +08:00
#if DEVELOPMENT_BUILD || DEBUG
PlayerPrefs.SetInt("ServerIndex", serverIndex);
#else
var serverInfos = AppConfig.Instance.GetServerInfo();
AppConfig.Instance.Select(serverIndex);
#endif
Gameplay.Net.Actor.Instance.StartLogin(NLDPB.LoginType.Phxh, loginSaveData.account);
}
2024-09-10 11:41:36 +08:00
void PhoneAutoLogin()
{
PhoneVerifyTool.Instance.RefreshTokenTime = loginSaveData.AuthCodeUpdateTime;
PhoneVerifyTool.Instance.RefreshToken = loginSaveData.AuthCode;
PhoneVerifyTool.Instance.PhoneNumber = loginSaveData.phoneNumber;
PlayerPrefs.SetInt("ServerIndex", serverIndex);
DebugUtil.Log("已有手机号登录凭证,自动登录");
//OnPhoneCodeLoginClick();
2024-09-26 19:16:39 +08:00
BIManager.Instance.TrackEvent("login_check", new Dictionary<string, object>
{
{"method",1 }//1表示自动登录
});
2024-09-10 11:41:36 +08:00
PhoneVerifyTool.Instance.RefreshTokenRequest((i, msg) =>
{
if (i == 0)
{
Actor.Instance.StartLogin(NLDPB.LoginType.Phxhphone, loginSaveData.phoneNumber);
}
else
{
CommonUtils.ShowMessageTips(msg);
loginSaveData.AuthCode = string.Empty;
loginSaveData.AuthCodeUpdateTime = 0;
StorageMgr.Instance.SyncForce = true;
2024-09-10 11:41:36 +08:00
SetLoginType(LoginType.PhoneCode);
}
});
}
void ShowLoginPanel()
{
2024-09-13 17:37:36 +08:00
#if SDK_TAPTAP
SetLoginType(LoginType.TapTap);
2024-11-05 19:34:28 +08:00
#elif SDK_BILIBILI
SetLoginType(LoginType.Bilibili);
2024-09-13 17:37:36 +08:00
#else
if (loginSaveData.LoginByPhone)
2024-09-10 11:41:36 +08:00
{
SetLoginType(LoginType.PhoneCode);
}
else
{
SetLoginType(LoginType.Account);
}
2024-09-13 17:37:36 +08:00
#endif
2024-09-10 11:41:36 +08:00
}
2024-09-13 17:37:36 +08:00
async void OnNoticeClick()
{
2024-09-10 11:41:36 +08:00
await UI_NoticeController.Open();
}
2024-09-18 17:51:22 +08:00
private async void OnStartGame()
2024-09-10 11:41:36 +08:00
{
2024-09-13 17:37:36 +08:00
#if SDK_TAPTAP
2024-09-18 17:51:22 +08:00
try
{
TapTapAccount account = await TapTapLogin.Instance.GetCurrentTapAccount();
if (null == account)
ShowLoginPanel();
else
2024-09-25 16:39:30 +08:00
Actor.Instance.StartLogin(NLDPB.LoginType.TapTap, "");
2024-09-18 17:51:22 +08:00
}
catch (Exception e)
{
DebugUtil.LogError($"获取用户信息失败 {e.Message}");
}
2024-09-13 17:37:36 +08:00
return;
#endif
2024-09-26 19:16:39 +08:00
if (loginSaveData.LoginByPhone && loginSaveData.AuthCodeUpdateTime > DateTimeOffset.UtcNow.ToUnixTimeSeconds())//手机号Token自动登录
2024-09-10 11:41:36 +08:00
{
PhoneAutoLogin();
}
#if !LOGIN_PHONE
else if (loginSaveData.LoginByAccount && loginSaveData.rememberPassword && LoginController.Instance.AutoLogin)//保存有数据且为初次登录时尝试自动登录
{
DebugUtil.Log("已有账号密码,自动登录");
2024-09-26 19:16:39 +08:00
BIManager.Instance.TrackEvent("login_check", new Dictionary<string, object>
{
{"method",1 }//1表示自动登录
});
2024-09-10 11:41:36 +08:00
LoginAction();
DebugUtil.Log("点击登录按钮,拉起加载图标遮挡");
}
else if (loginSaveData.LoginByAccount)
{
SetLoginType(LoginType.Account);
}
#endif
else
{
SetLoginType(LoginType.PhoneCode);
}
}
#endregion
#region RegisterEvent
void OnLoginOK()
{
2024-09-03 17:07:34 +08:00
//loginOK = true;
HideLoginPanel();
2024-09-10 11:41:36 +08:00
loginSaveData = StorageMgr.Instance.GetStorage<LoginData>("LoginData");
if (loginSaveData == null)
loginSaveData = new();
2024-09-10 11:41:36 +08:00
if (tempSaveData != null)
loginSaveData.SetData(tempSaveData);
2024-09-10 11:41:36 +08:00
if (loginSaveData.LoginByAccount)
{
loginSaveData.LoginByPhone = false;
}
2024-09-10 11:41:36 +08:00
StorageMgr.Instance.SyncForce = true;
2024-07-24 19:24:11 +08:00
2024-09-10 11:41:36 +08:00
Text_UID.gameObject.SetActive(true);
Text_UID.text = "UID: " + Actor.Instance.Base.GetProp(ActorProp.ActorId);
BIManager.Instance.TrackEvent(BIManager.BI_GameStart, param: new System.Collections.Generic.Dictionary<string, object>
{
{"login_finish" , 1 }
});
#if SDK_TAPTAP
//TAPTAP不走自带实名认证
2024-10-16 19:19:32 +08:00
CloseWindow();
Actor.Instance.OnEnterGame();
#else
2024-09-10 11:41:36 +08:00
var adultStatus = (int)Actor.Instance.Logic.GetCount((uint)LogicID.AdultAuthStatus);
if (adultStatus == (int)AAStatus.AasNone)
{
DebugUtil.Log("未实名认证");
UI_NoticeWindowController.Open().Forget();
}
2024-11-04 15:22:27 +08:00
else if (adultStatus == (int)AAStatus.AasUnderEighteen && !CommonUtils.IsUnderagePlayTimeAllowed())
{
DebugUtil.Log("未成年时段限制");
WaitingForServer.Instance.EventClear();
}
2024-09-03 17:07:34 +08:00
else
{
2024-10-16 19:19:32 +08:00
CloseWindow();
2024-09-03 17:07:34 +08:00
Actor.Instance.OnEnterGame();
}
#endif
2024-09-03 17:07:34 +08:00
}
2024-08-15 12:51:51 +08:00
void OnLogoutComplete()
{
if (loginSaveData.LoginByPhone)
{
SetLoginType(LoginType.PhoneCode);
}
else
{
SetLoginType(LoginType.Account);
}
}
2024-09-10 11:41:36 +08:00
void OnCancelCurConnect()
{
if (LoginController.Instance.IsLogin)//需要断开连接
{
DebugUtil.Log("登出!断开连接");
Actor.Instance.OnDisConnect();
Actor.Instance.OnLogout();
}
ShowLoginPanel();
}
2024-08-07 15:45:10 +08:00
void OnPhoneCodeRequestFailed(string errorMsg)
{
CommonUtils.ShowMessageTips(errorMsg);
2024-08-13 12:30:13 +08:00
//isTimer = false;
debugLoginWindow.isTimer = false;
releaseLoginWindow.isTimer = false;
2024-08-07 15:45:10 +08:00
}
void OnPhoneCodeLoginSuc()
{
if (tempSaveData != null)
{
tempSaveData.AccessToken = PhoneVerifyTool.Instance.AccessTokenCode;
2024-09-10 11:41:36 +08:00
tempSaveData.AuthCode = PhoneVerifyTool.Instance.RefreshToken;
2024-08-09 14:30:52 +08:00
tempSaveData.AuthCodeUpdateTime = PhoneVerifyTool.Instance.RefreshTokenTime;
tempSaveData.ClearAccountLoginData();
tempSaveData.LoginByPhone = true;
2024-09-10 11:41:36 +08:00
tempSaveData.LoginByAccount = false;
}
else
{
DebugUtil.LogWarning("暂存登录数据为空!");
2024-08-07 15:45:10 +08:00
}
2024-09-10 11:41:36 +08:00
loginSaveData.AuthCode = PhoneVerifyTool.Instance.RefreshToken;
2024-08-09 14:30:52 +08:00
loginSaveData.AuthCodeUpdateTime = PhoneVerifyTool.Instance.RefreshTokenTime;
2024-08-23 13:11:56 +08:00
DebugUtil.Log("登录token" + PhoneVerifyTool.Instance.AccessTokenCode);
2024-08-07 15:45:10 +08:00
DebugUtil.Log("验证码登录成功!保存登录凭证:" + loginSaveData.AuthCode);
}
void OnPhoneCodeLoginFailed(string errorMsg)
{
CommonUtils.ShowMessageTips(errorMsg);
}
#endregion
2024-07-15 12:20:03 +08:00
class LoginData
{
/// <summary>
2024-07-16 15:24:41 +08:00
/// 用账号密码成功登录
/// </summary>
2024-07-15 12:20:03 +08:00
public bool LoginByAccount = false;
public string account;
public string password;
public bool rememberPassword;
/// <summary>
/// 用手机验证成功登录
/// </summary>
public bool LoginByPhone = false;
2024-07-15 12:20:03 +08:00
public string phoneNumber;
public string AccessToken;
2024-09-03 17:07:34 +08:00
/// <summary>
/// 刷新凭证
/// </summary>
2024-08-07 15:45:10 +08:00
public string AuthCode;
2024-08-09 14:30:52 +08:00
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;
}
2024-07-15 12:20:03 +08:00
}
}
2024-08-15 12:51:51 +08:00
2024-09-03 17:07:34 +08:00
/// <summary>
/// 用于记录登陆状态
/// </summary>
2024-08-15 12:51:51 +08:00
public class LoginController : Singlenton<LoginController>
{
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;
2024-08-15 12:51:51 +08:00
isLogin = false;
}
public void OnLoginOK()
{
//autoLogin = false;//登录成功后关闭自动登录
2024-08-15 12:51:51 +08:00
isLogin = true;
2024-09-18 15:25:47 +08:00
//是否为新注册用户
int completeStepId = (int)Actor.Instance.Logic.GetCount((uint)LogicID.NewGuideProgress);
if (completeStepId == 0)
{
NetHelper.SaveGuideProgress(1);
2024-09-18 18:18:34 +08:00
#if SDK_TALKINGDATA
2024-10-28 14:36:22 +08:00
var profile = TalkingDataProfile.CreateProfile();
if (profile != null)
profile.SetName(Actor.Instance.Base.Nickname);
2024-10-28 14:36:22 +08:00
BIManager.Instance.TrackEvent(TalkingDataEventName.Register, param1: profile);
2024-09-18 18:18:34 +08:00
#endif
2024-09-18 15:25:47 +08:00
BIManager.Instance.TrackEvent(BIManager.BI_GameStart, param: new System.Collections.Generic.Dictionary<string, object>
{
{"register_finish",1 }
2024-09-18 15:25:47 +08:00
});
}
2024-08-15 12:51:51 +08:00
}
}