killapp/Assets/Scripts/UI/Pages/Login/SubPages/ThirdPartyBindPanel.cs

106 lines
3.0 KiB
C#
Raw Normal View History

2026-04-16 14:57:19 +08:00
using UnityEngine;
using UnityEngine.UI;
using Kill.Managers;
using Kill.UI.Components;
namespace Kill.UI.Pages
{
/// <summary>
/// 第三方登录绑定页面
/// </summary>
public class ThirdPartyBindPanel : LoginSubPageBase
{
[Header("登录按钮")]
public Button wechatBtn;
public Button qqBtn;
public Button appleBtn;
public Button googleBtn; // 谷歌登录按钮
[Header("返回")]
public Button backBtn;
protected override void OnInitialize()
{
if (wechatBtn != null)
wechatBtn.onClick.AddListener(() => OnThirdPartyLogin("wechat"));
if (qqBtn != null)
qqBtn.onClick.AddListener(() => OnThirdPartyLogin("qq"));
if (appleBtn != null)
appleBtn.onClick.AddListener(() => OnThirdPartyLogin("apple"));
if (googleBtn != null)
googleBtn.onClick.AddListener(OnGoogleLogin);
if (backBtn != null)
backBtn.onClick.AddListener(GoBack);
// Android 平台显示谷歌登录按钮
#if UNITY_ANDROID && !UNITY_EDITOR
if (googleBtn != null)
googleBtn.gameObject.SetActive(true);
#else
if (googleBtn != null)
googleBtn.gameObject.SetActive(false);
#endif
}
/// <summary>
/// 谷歌登录
/// </summary>
private void OnGoogleLogin()
{
Debug.Log("开始谷歌登录...");
LoadingUI.Show();
FirebaseAuthManager.Instance.SignInWithGoogle(
onSuccess: (result) =>
{
LoadingUI.Hide();
Debug.Log($"谷歌登录成功: {result.DisplayName}, FirebaseID: {result.FirebaseUserId}");
// 调用后端绑定接口
BindGoogleAccount(result);
},
onError: (error) =>
{
LoadingUI.Hide();
Debug.LogError($"谷歌登录失败: {error}");
ToastUI.Show("100036"); // 登录失败提示
}
);
}
/// <summary>
/// 绑定谷歌账号到本系统
/// </summary>
private void BindGoogleAccount(GoogleLoginResult googleResult)
{
string email = LoginPageCtrl.Instance.GetCurrentEmail();
}
private void OnThirdPartyLogin(string platform)
{
Debug.Log($"第三方登录: {platform}");
// TODO: 调用对应平台的SDK
switch (platform)
{
case "wechat":
// 微信登录
break;
case "qq":
// QQ登录
break;
case "apple":
// Apple登录
break;
}
}
}
}