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

1150 lines
39 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Cysharp.Threading.Tasks;
using Framework;
using Gameplay;
using Gameplay.FirstTimeFlow;
using Gameplay.Net;
using NLDPB;
using PhxhSDK;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
using Toggle = UnityEngine.UI.Toggle;
#if SDK_TAPTAP
using TapSDK.Login;
#elif SDK_BILIBILI
using PhxhSDK.AOT.Bilibili;
#endif
public class UI_StartGameInterfaceController : UIWindow
{
enum LoginType
{
Account,
PhoneCode,
TapTap,
Bilibili,
#if UNITY_IOS
Apple,
#endif
}
#region UI_obj
//UI GameObj
///Auto Gen Start///
public Image Image_BgDark;
public Button Button_StartGame;
public Image Image_LoginBg;
public TMP_Text Text_AccountLogin;
public Button Button_AccountLogin;
public Image Image_YellowLine_Account;
public TMP_Text Text_VerifyCodeLogin;
public Button Button_VerifyCodeLogin;
public Image Image_YellowLine_VerifyCode;
public Button Button_Debug;
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 Button Button_AppleClick;
public Button Button_GoogleClick;
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;
public Button Button_AgeTip;
///Auto Gen End///
/// <summary>
/// TapTap登录按钮
/// </summary>
private Button buttonTapTap;
/// <summary>
/// Bilibili登录按钮
/// </summary>
private Button buttonBilibili;
#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 TMP_Text Text_Agreement;
public bool isTimer;
public Button Button_Login;
public Button Button_Debug;
public Button Button_AccountLogin;
public GameObject Image_line;
public Button Button_VerifyCodeLogin;
public GameObject AccountLoginPanel;
public TMP_Dropdown ServerSelecter;
public Image Image_YellowLine_Account;
public Image Image_YellowLine_VerifyCode;
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 Button AppleBtn;
public LoginWindow(GameObject root,
UnityAction<String> PhoneNumberEdit,
UnityAction<String> CodeEdit,
UnityAction<bool> AgreementAccept,
UnityAction PhoneCodeLogin,
UnityAction SendPhoneRequest) : base(root)
{
AccountLoginPanel = root.transform.Find("Image_LoginBg/AccountLogin").gameObject;
VerifyCodeLoginPanel = root.transform.Find("Image_LoginBg/VerifyCodeLogin").gameObject;
ServerSelecter = root.transform.Find("Image_LoginBg/ALDropdown").GetComponent<TMP_Dropdown>();
Button_Debug = GetComponent<Button>("Image_LoginBg/Top/Button_Debug");
Button_AccountLogin = GetComponent<Button>("Image_LoginBg/Top/ImageBg/AccountLogin/Button_AccountLogin");
Image_line = FindObj("Image_LoginBg/Top/ImageBg/ImageBg (1)");
Button_VerifyCodeLogin = GetComponent<Button>("Image_LoginBg/Top/ImageBg/VerifyCodeLogin/Button_VerifyCodeLogin");
Toggle_Agreement = GetComponent<Toggle>("Image_LoginBg/VerifyCodeLogin/Mid/Info/Agreement/Toggle_Agreement_2");
Toggle_Agreement_Account = GetComponent<Toggle>("Image_LoginBg/AccountLogin/Mid/Info/Agreement/Toggle_Agreement_1");
Image_YellowLine_Account = GetComponent<Image>("Image_LoginBg/Top/ImageBg/AccountLogin/Button_AccountLogin/Image_YellowLine_Account");
Image_YellowLine_VerifyCode = GetComponent<Image>("Image_LoginBg/Top/ImageBg/VerifyCodeLogin/Button_VerifyCodeLogin/Image_YellowLine_VerifyCode");
Toggle_RememberPassword = GetComponent<Toggle>("Image_LoginBg/AccountLogin/Mid/Info/RememberPassword/Toggle_RememberPassword");
InputField_Account = GetComponent<TMP_InputField>("Image_LoginBg/AccountLogin/Mid/Account/InputField_Account");
InputField_Password = GetComponent<TMP_InputField>("Image_LoginBg/AccountLogin/Mid/Password/InputField_Password");
Button_Login_Account = GetComponent<Button>("Image_LoginBg/AccountLogin/Bottom/Button_Login_1");
Button_Login = GetComponent<Button>("Image_LoginBg/VerifyCodeLogin/Bottom/Button_Login_2");
Button_GetVerifyCode = GetComponent<Button>("Image_LoginBg/VerifyCodeLogin/Mid/VerifyCode/Button_GetVerifyCode");
Button_GetVerifyCodeCooling = GetComponent<Button>("Image_LoginBg/VerifyCodeLogin/Mid/VerifyCode/Button_GetVerifyCodeCooling");
InputField_PhoneNumber = GetComponent<TMP_InputField>("Image_LoginBg/VerifyCodeLogin/Mid/Phone/InputField_PhoneNumber");
InputField_VerifyCode = GetComponent<TMP_InputField>("Image_LoginBg/VerifyCodeLogin/Mid/VerifyCode/InputField_VerifyCode");
Text_Agreement = GetComponent<TMP_Text>("Image_LoginBg/VerifyCodeLogin/Mid/Info/Agreement/Text_Agreement_2");
Text_Agreement_Account = GetComponent<TMP_Text>("Image_LoginBg/AccountLogin/Mid/Info/Agreement/Text_Agreement_1");
AppleBtn = GetComponent<Button>("Image_LoginBg/Bottom/LogAccountNode/Button_AppleClick");
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 });
}
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;
}
SetLinkText(Toggle_Agreement, Text_Agreement);
SetLinkText(Toggle_Agreement_Account, Text_Agreement_Account);
#if !UNITY_IOS
AppleBtn.gameObject.SetActive(false);
#endif
bool hasShownBtn = false;
var btnParent = FindObj("Image_LoginBg/Bottom/LogAccountNode").transform;
foreach (Transform child in btnParent)
{
if (child.gameObject.activeSelf)
{
hasShownBtn = true;
break;
}
}
btnParent.parent.gameObject.SetActive(hasShownBtn);
if (!hasShownBtn)
{
AccountLoginPanel.transform.localPosition = new Vector3(0, 0, 0);
VerifyCodeLoginPanel.transform.localPosition = new Vector3(0, 0, 0);
}
}
public virtual void SetLoginType(LoginType loginType)
{
AccountLoginPanel.SetActive(loginType == LoginType.Account);
VerifyCodeLoginPanel.SetActive(loginType == LoginType.PhoneCode);
}
public virtual 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;
}
}
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);
}
protected void SetLinkText(Toggle agreement, TMP_Text text)
{
LinkText linkText = text.GetComponent<LinkText>();
if (linkText == null)
{
DebugUtil.Log("LinkText is null");
}
else
{
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(CommonUtils.GetLocalizeText("uilogin_AgreementText"), url1, url2, url3);
linkText.SetText(content);
}
linkText.SetOtherAreaClicked(() => agreement.isOn = !agreement.isOn);
}
public void SetDebugMode(bool isOn)
{
Image_line.gameObject.SetActive(isOn);
Button_AccountLogin.transform.parent.gameObject.SetActive(isOn);
//ServerSelecter.gameObject.SetActive(isOn);
Button_Debug.gameObject.SetActive(false);
//
//if (IsDevelopmentOrDebug())
//{
// Button_Debug.gameObject.SetActive(!isOn);
//}
}
/// <summary>
/// 检查当前构建是否为开发版本或调试版本。
/// </summary>
/// <returns>如果是开发或调试版本,则返回 true否则返回 false。</returns>
bool IsDevelopmentOrDebug()
{
#if DEVELOPMENT_BUILD || DEBUG
return true;
#else
return false;
#endif
}
}
#endregion
LoginWindow curShownWindow;
LoginType loginType;
LoginData loginSaveData;
/// <summary>
/// 确认登录后写入数据 (由于切换账号会清空本地数据,在这里做数据缓存)
/// </summary>
LoginData tempSaveData;
bool loginOK = false;
int serverIndex = 0;
// deal with input data
public override void PreLoad(object data = null)
{
loginSaveData = StorageMgr.Instance.GetStorage<LoginData>("LoginData");
if (loginSaveData == null)
loginSaveData = new();
AppleLoginManager.Instance.SetCacheLoginInfo(loginSaveData.AppleAccessToken, loginSaveData.AppleID,
loginSaveData.AppleTimestamp);
}
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);
buttonTapTap = GetComponent<Button>("TapTapBtn");
buttonBilibili = GetComponent<Button>("BilibiliBtn");
Button_AppleClick = GetComponent<Button>("UI_LoginWindow/Image_LoginBg/Bottom/LogAccountNode/Button_AppleClick");
curShownWindow = new(FindObj("UI_LoginWindow"), PhoneEdit, PhoneVerifyCodeEdit, OnAgreementAccept, OnPhoneCodeLoginClick, SendPhoneCodeRequest);
AudioManager.Instance.PlayAudio("bgm_login", AudioCriManager.EPlayType.Music, null, true);
var Button_AgeTip = GetComponent<Button>("Button_AgeTip");
#region EventManager
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.PhoneCodeLoginSuc, OnPhoneCodeLoginSuc);
EventManager.Instance.Register<string>(EventManager.EventName.PhoneCodeLoginFail, OnPhoneCodeLoginFailed);
EventManager.Instance.Register<string>(EventManager.EventName.PhoneCodeRequsetFail, OnPhoneCodeRequestFailed);
EventManager.Instance.Register<AppleLoginManager.AppleLoginInfo>(EventManager.EventName.AppleVerifySuccess, OnNetVerifyAppleLoginSuccess);
EventManager.Instance.Register(EventManager.EventName.AppleLoginStateFail, OnCheckAppleLoginStateFail);
#endregion
#if LOGIN_PHONE // 使用手机登录界面
curShownWindow.SetDebugMode(false);
#else
curShownWindow.SetDebugMode(true);
#endif
HideLoginPanel();
var index = PlayerPrefs.GetInt("ServerIndex", 0);
serverIndex = index;
AppConfig.Instance.Select(index);
bool selectServer = false;
// 开发环境下的特殊处理
#if DEVELOPMENT_BUILD || DEBUG
selectServer = true;
#endif
if (selectServer)
{
SetupDebugServerSelector();
}
/// <summary>
/// 设置开发环境下的服务器选择器
/// </summary>
void SetupDebugServerSelector()
{
curShownWindow.ServerSelecter.gameObject.SetActive(true);
curShownWindow.ServerSelecter.onValueChanged.AddListener(OnServerSelected);
// ...
/// <summary>
/// 处理服务器选择事件
/// </summary>
/// <param name="selectedIndex">选中的服务器索引</param>
void OnServerSelected(int selectedIndex)
{
DebugUtil.Log("选择服务器:" + selectedIndex);
AppConfig.Instance.Select(selectedIndex);
serverIndex = selectedIndex;
}
}
#region BindButton
BindButton(Button_AppleClick, AppleLogin);
BindButton(Button_AgeTip, OnAgeTipsClick);
BindButton(Button_AccountLogin, () => SetLoginType(LoginType.Account));
BindButton(Button_VerifyCodeLogin, () => SetLoginType(LoginType.PhoneCode));
BindButton(Button_Login_1, OnButtonLogin);
BindButton(Button_UserCenter, ShowLoginPanel);
BindButton(Button_Notice, OnNoticeClick);
BindButton(buttonTapTap, OnTapTapBtnClick);
//BindButton(buttonBilibili, OnBilibiliClick);
BindButton(Button_StartGame, OnStartGame);
#endregion
curShownWindow.Toggle_RememberPassword.onValueChanged.AddListener(OnRememberPassword);
curShownWindow.InputField_Account.onValueChanged.AddListener(AccountEdit);
curShownWindow.InputField_Password.onValueChanged.AddListener(PasswordEdit);
Text_Version.text = "version:" + Application.version;
Text_UID.gameObject.SetActive(false);
}
/// <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://账号密码登录
curShownWindow.Image_YellowLine_Account.gameObject.SetActive(true);
curShownWindow.Image_YellowLine_VerifyCode.gameObject.SetActive(false);
curShownWindow.Toggle_RememberPassword.isOn = loginSaveData.rememberPassword;
curShownWindow.Toggle_Agreement_Account.isOn = loginSaveData.agreement;
curShownWindow.VerifyCodeLoginPanel.SetActive(false);
curShownWindow.AccountLoginPanel.SetActive(true);
if (loginSaveData.account != default)
{
curShownWindow.InputField_Account.text = loginSaveData.account;
}
if (loginSaveData.password != default && loginSaveData.rememberPassword)
{
curShownWindow.InputField_Password.text = loginSaveData.password;
}
else
{
curShownWindow.InputField_Password.text = string.Empty;
}
break;
case LoginType.PhoneCode://手机号验证码登录
curShownWindow.Image_YellowLine_Account.gameObject.SetActive(false);
curShownWindow.Image_YellowLine_VerifyCode.gameObject.SetActive(true);
curShownWindow.Toggle_Agreement.isOn = loginSaveData.agreement;
curShownWindow.CheckPhoneCodeButton();
break;
case LoginType.TapTap:
{
curShownWindow.IsScaleShow = false;
buttonTapTap.gameObject.IsScaleShow(true);
buttonBilibili.gameObject.IsScaleShow(false);
}
break;
case LoginType.Bilibili:
{
curShownWindow.IsScaleShow = false;
buttonTapTap.gameObject.IsScaleShow(false);
buttonBilibili.gameObject.IsScaleShow(true);
}
break;
default:
DebugUtil.LogError("SetLoginType error");
break;
}
curShownWindow.CheckLoginButton(loginType, loginSaveData.agreement);
}
void HideLoginPanel()
{
//Image_LoginBg.gameObject.SetActive(false);
curShownWindow.IsScaleShow = false;
buttonTapTap.gameObject.IsScaleShow(false);
buttonBilibili.gameObject.IsScaleShow(false);
Button_StartGame.gameObject.SetActive(true);
Button_Notice.gameObject.SetActive(true);
#if !SDK_BILIBILI || DEVELOPMENT_BUILD || DEBUG
Button_UserCenter.gameObject.SetActive(true);
#else
Button_UserCenter.gameObject.SetActive(false);
#endif
}
//invoke when destroy
public override void OnRelease()
{
base.OnRelease();
curShownWindow.isTimer = false;
EventManager.Instance.Unregister(EventManager.EventName.RealNameVerifyCancel, OnCancelCurConnect);
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<AppleLoginManager.AppleLoginInfo>(EventManager.EventName.AppleVerifySuccess, OnNetVerifyAppleLoginSuccess);
EventManager.Instance.Unregister(EventManager.EventName.AppleLoginStateFail, OnCheckAppleLoginStateFail);
AudioManager.Instance.StopAll();
AudioManager.Instance.ReleaseAllAudios();
//EventManager.Instance.Unregister(EventManager.EventName.NetError, ConnectNetError);
//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;
curShownWindow.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;
}
loginSaveData.LoginByAccount = true;
tempSaveData = new(loginSaveData);//暂存登录数据
LoginAction();
BIManager.Instance.TrackEvent("login_check", new Dictionary<string, object>
{
{"method",0 }//0表示手动输入登录
});
DebugUtil.Log("点击登录按钮,拉起加载图标遮挡");
}
/// <summary>
/// 请求发送验证码
/// </summary>
void SendPhoneCodeRequest()
{
curShownWindow.CoolingTimer().Forget();
PhoneVerifyTool.Instance.PhoneNumber = loginSaveData.phoneNumber;
PhoneVerifyTool.Instance.PhoneCodeWebRequest();
//isTimer = true;
}
/// <summary>
/// 手机验证码登录
/// </summary>
void OnPhoneCodeLoginClick()
{
tempSaveData = new(loginSaveData);//暂存登录数据
PhoneVerifyTool.Instance.PhoneNumber = loginSaveData.phoneNumber;
PhoneVerifyTool.Instance.HttpVerifyCode = curShownWindow.InputField_VerifyCode.text;
#if DEVELOPMENT_BUILD || DEBUG
PlayerPrefs.SetInt("ServerIndex", serverIndex);
#else
var serverInfos = AppConfig.Instance.GetServerInfo();
AppConfig.Instance.Select(serverIndex);
#endif
BIManager.Instance.TrackEvent("login_check", new Dictionary<string, object>
{
{"method",0 }//0表示手动输入登录
});
Actor.Instance.StartLogin(NLDPB.LoginType.Phxhphone, loginSaveData.phoneNumber);
DebugUtil.Log("点击登录按钮,拉起加载图标遮挡");
}
/// <summary>
/// TapTap登录
/// </summary>
private void OnTapTapBtnClick()
{
#if SDK_TAPTAP
WaitingForServer.Instance.EventWaiting(WaitingForServer.EventName.TapTapLogin, false, false);
TapTapLogin.Instance.Logout();
Actor.Instance.StartLogin(NLDPB.LoginType.TapTap, "");
#endif
}
/// <summary>
/// Bilibili登录
/// </summary>
private void OnBilibiliClick()
{
#if SDK_BILIBILI
DebugUtil.Log("点击哔哩哔哩登录");
GSCSdkInterface.stopHeartbeat();
GSCSdkInterface.logout();
Actor.Instance.StartLogin(NLDPB.LoginType.BiliBili, "");
#endif
}
/// <summary>
/// 服务器登录
/// </summary>
void LoginAction()
{
#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);
}
void PhoneAutoLogin()
{
PhoneVerifyTool.Instance.RefreshTokenTime = loginSaveData.AuthCodeUpdateTime;
PhoneVerifyTool.Instance.RefreshToken = loginSaveData.AuthCode;
PhoneVerifyTool.Instance.PhoneNumber = loginSaveData.phoneNumber;
PlayerPrefs.SetInt("ServerIndex", serverIndex);
DebugUtil.Log("已有手机号登录凭证,自动登录");
//OnPhoneCodeLoginClick();
BIManager.Instance.TrackEvent("login_check", new Dictionary<string, object>
{
{"method",1 }//1表示自动登录
});
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;
SetLoginType(LoginType.PhoneCode);
}
});
}
void OnAgeTipsClick()
{
UI_AgeTipController.Open().Forget();
}
/// <summary>
/// 苹果登录
/// </summary>
private void AppleLogin()
{
if (!loginSaveData.agreement)
{
UITipsManager.ShowConfirmOne("登录提示", "请先勾选同意隐私协议", null);
return;
}
PlayerPrefs.SetInt("ServerIndex", serverIndex);
Actor.Instance.StartLogin(NLDPB.LoginType.Apple, "");
}
void ShowLoginPanel()
{
// 切换账户
AppleLoginManager.Instance.ClearAppleLoginInfo();
#if SDK_TAPTAP
SetLoginType(LoginType.TapTap);
//#elif SDK_BILIBILI
// SetLoginType(LoginType.Bilibili);
#elif LOGIN_PHONE
SetLoginType(LoginType.PhoneCode);
#else
if (loginSaveData.LoginByPhone)
{
SetLoginType(LoginType.PhoneCode);
}
else
{
SetLoginType(LoginType.Account);
}
#endif
}
async void OnNoticeClick()
{
await UI_NoticeController.Open();
}
private async void OnStartGame()
{
#if SDK_TAPTAP
try
{
TapTapAccount account = await TapTapLogin.Instance.GetCurrentTapAccount();
if (null == account)
ShowLoginPanel();
else
Actor.Instance.StartLogin(NLDPB.LoginType.TapTap, "");
}
catch (Exception e)
{
DebugUtil.LogError($"获取用户信息失败 {e.Message}");
}
return;
#endif
#if SDK_BILIBILI
try
{
DebugUtil.Log("点击哔哩哔哩登录");
GSCSdkInterface.androidCheckLogin();
await UniTask.WaitUntil(() => { return !GSCSdkInterface.CheckLoging; });
if (GSCSdkInterface.IsLogin)
{
DebugUtil.Log("已登录状态,进入游戏");
Actor.Instance.StartLogin(NLDPB.LoginType.BiliBili, "");
}
else
{
DebugUtil.Log("未登录状态,拉起登录界面");
OnBilibiliClick();//ShowLoginPanel();
}
}
catch (Exception e)
{
DebugUtil.LogError($"获取用户信息失败 {e.Message}");
}
return;
#endif
if (loginSaveData.LoginByPhone && loginSaveData.AuthCodeUpdateTime > DateTimeOffset.UtcNow.ToUnixTimeSeconds())//手机号Token自动登录
{
PhoneAutoLogin();
}
#if !LOGIN_PHONE
else if (loginSaveData.LoginByAccount && loginSaveData.rememberPassword && LoginController.Instance.AutoLogin)//保存有数据且为初次登录时尝试自动登录
{
DebugUtil.Log("已有账号密码,自动登录");
BIManager.Instance.TrackEvent("login_check", new Dictionary<string, object>
{
{"method",1 }//1表示自动登录
});
LoginAction();
DebugUtil.Log("点击登录按钮,拉起加载图标遮挡");
}
else if (loginSaveData.LoginByAccount)
{
SetLoginType(LoginType.Account);
}
#endif
else if(loginSaveData.AppleLogin && AppleLoginManager.Instance.AppleLoginInfoIsExist() && !AppleLoginManager.Instance.CheckExpirationTime())
{
AppleLogin();
}
else
{
SetLoginType(LoginType.PhoneCode);
}
}
#endregion
#region RegisterEvent
void OnLoginOK()
{
//loginOK = true;
HideLoginPanel();
loginSaveData = StorageMgr.Instance.GetStorage<LoginData>("LoginData");
if (loginSaveData == null)
loginSaveData = new();
if (tempSaveData != null)
loginSaveData.SetData(tempSaveData);
if (loginSaveData.LoginByAccount)
{
loginSaveData.LoginByPhone = false;
}
StorageMgr.Instance.SyncForce = true;
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 || SDK_BILIBILI || OverseaDev
//TAPTAP不走自带实名认证
CloseWindow();
Actor.Instance.OnEnterGame();
#else
var adultStatus = (int)Actor.Instance.Logic.GetCount((uint)LogicID.AdultAuthStatus);
if (adultStatus == (int)AAStatus.AasNone)
{
DebugUtil.Log("未实名认证");
UI_NoticeWindowController.Open().Forget();
}
else if (adultStatus == (int)AAStatus.AasUnderEighteen && !CommonUtils.IsUnderagePlayTimeAllowed())
{
DebugUtil.Log("未成年时段限制");
WaitingForServer.Instance.EventClear();
}
else
{
CloseWindow();
Actor.Instance.OnEnterGame();
}
#endif
}
void OnLogoutComplete()
{
if (loginSaveData.LoginByPhone)
{
SetLoginType(LoginType.PhoneCode);
}
else
{
SetLoginType(LoginType.Account);
}
}
void OnCancelCurConnect()
{
if (LoginController.Instance.IsLogin)//需要断开连接
{
DebugUtil.Log("登出!断开连接");
Actor.Instance.OnDisConnect();
Actor.Instance.OnLogout();
}
ShowLoginPanel();
}
void OnPhoneCodeRequestFailed(string errorMsg)
{
CommonUtils.ShowMessageTips(errorMsg);
//isTimer = false;
curShownWindow.isTimer = false;
}
void OnPhoneCodeLoginSuc()
{
if (tempSaveData != null)
{
tempSaveData.AccessToken = PhoneVerifyTool.Instance.AccessTokenCode;
tempSaveData.AuthCode = PhoneVerifyTool.Instance.RefreshToken;
tempSaveData.AuthCodeUpdateTime = PhoneVerifyTool.Instance.RefreshTokenTime;
tempSaveData.ClearAccountLoginData();
tempSaveData.LoginByPhone = true;
tempSaveData.LoginByAccount = false;
}
else
{
DebugUtil.LogWarning("暂存登录数据为空!");
}
loginSaveData.AuthCode = PhoneVerifyTool.Instance.RefreshToken;
loginSaveData.AuthCodeUpdateTime = PhoneVerifyTool.Instance.RefreshTokenTime;
DebugUtil.Log("登录token" + PhoneVerifyTool.Instance.AccessTokenCode);
DebugUtil.Log("验证码登录成功!保存登录凭证:" + loginSaveData.AuthCode);
}
void OnPhoneCodeLoginFailed(string errorMsg)
{
CommonUtils.ShowMessageTips(errorMsg);
}
/// <summary>
/// 服务器验证苹果登录成功
/// </summary>
private void OnNetVerifyAppleLoginSuccess(AppleLoginManager.AppleLoginInfo appleLoginInfo)
{
if (tempSaveData != null)
{
tempSaveData.ClearAccountLoginData();
tempSaveData.AppleLogin = true;
tempSaveData.AppleID = appleLoginInfo.AppleID;
tempSaveData.AppleAccessToken = appleLoginInfo.AccessTokenID;
tempSaveData.AppleTimestamp = appleLoginInfo.Timestamp.ToString();
}
loginSaveData.AppleID = appleLoginInfo.AppleID;
loginSaveData.AppleAccessToken = appleLoginInfo.AccessTokenID;
loginSaveData.AppleTimestamp = appleLoginInfo.Timestamp.ToString();
loginSaveData.AppleLogin = true;
StorageMgr.Instance.SyncForce = true;
DebugUtil.Log("苹果登录成功, 缓存用户ID:【{0}】, 过期时间:【{1}】, accessToken【{2}】", appleLoginInfo.AppleID,
appleLoginInfo.Timestamp, appleLoginInfo.AccessTokenID);
}
private void OnCheckAppleLoginStateFail()
{
if (tempSaveData != null)
{
tempSaveData.ClearAppleLoginData();
}
loginSaveData.ClearAppleLoginData();
StorageMgr.Instance.SyncForce = true;
DebugUtil.Log("苹果凭证失效, 清除缓存");
}
#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;
/// <summary>
/// 刷新凭证
/// </summary>
public string AuthCode;
public long AuthCodeUpdateTime;
/// <summary>
/// 苹果登录数据
/// </summary>
public bool AppleLogin = false;
public string AppleAccessToken;
public string AppleID;
public string AppleTimestamp;
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;
this.AppleLogin = loginData.AppleLogin;
this.AppleAccessToken = loginData.AppleAccessToken;
}
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;
this.AppleLogin = loginData.AppleLogin;
this.AppleAccessToken = loginData.AppleAccessToken;
}
public void ClearAccountLoginData()
{
LoginByAccount = false;
account = string.Empty;
password = string.Empty;
rememberPassword = false;
}
public void ClearAppleLoginData()
{
AppleLogin = false;
AppleAccessToken = string.Empty;
AppleID = string.Empty;
}
}
}
/// <summary>
/// 用于记录登陆状态
/// </summary>
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;
isLogin = false;
}
public void OnLoginOK()
{
//autoLogin = false;//登录成功后关闭自动登录
isLogin = true;
//是否为新注册用户
int firstId = (int)Actor.Instance.Logic.GetCount((uint)LogicID.NoviceProcessId);
if ((int)E_FirstTimeFlow.NewCreate == firstId) // 是新账户
{
NetHelper.SaveGuideProgress(LogicID.NoviceProcessId, (int)E_FirstTimeFlow.OldCreate); // 保存该值,第二次进入就不是新账户了
#if SDK_BILIBILI
GSCSdkInterface.createRole(Actor.Instance.Base.Nickname, Actor.Instance.Base.AccountID); // 创建角色
#endif
#if SDK_TALKINGDATA
BIManager.Instance.SetUserProperty(TalkingDataProfileParamName.Name, Actor.Instance.Base.Nickname);
BIManager.Instance.TrackEvent(TalkingDataEventName.Register, null);
#endif
}
#if SDK_TALKINGDATA
BIManager.Instance.SetUserProperty(TalkingDataProfileParamName.Name, Actor.Instance.Base.Nickname);
BIManager.Instance.TrackEvent(TalkingDataEventName.Login, null);
#endif
#if SDK_BILIBILI
GSCSdkInterface.startHeartbeat();
GSCSdkInterface.notifyZone(Actor.Instance.Base.AccountID, Actor.Instance.Base.Nickname); // 通知区服
#endif
}
}