121 lines
3.1 KiB
C#
121 lines
3.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Kill.Base;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
|
|
namespace Kill.UI
|
|
{
|
|
public class HomePageCtrl : MonoBehaviour
|
|
{
|
|
public InputField emailInput;
|
|
public InputField passwordInput;
|
|
public Button loginButton;
|
|
public Button registerButton;
|
|
public Button logoutButton;
|
|
public Text info;
|
|
|
|
// 存储待执行的UI更新操作
|
|
private List<Action> pendingUIUpdates = new List<Action>();
|
|
|
|
void Start()
|
|
{
|
|
Init();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// 执行所有挂起的UI更新
|
|
if (pendingUIUpdates.Count > 0)
|
|
{
|
|
foreach (var update in pendingUIUpdates)
|
|
{
|
|
update?.Invoke();
|
|
}
|
|
pendingUIUpdates.Clear();
|
|
}
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
loginButton.onClick.AddListener(() =>
|
|
{
|
|
Login();
|
|
});
|
|
registerButton.onClick.AddListener(() =>
|
|
{
|
|
Register();
|
|
});
|
|
logoutButton.onClick.AddListener(() =>
|
|
{
|
|
Logout();
|
|
});
|
|
|
|
CheckLoginAndNavigate();
|
|
}
|
|
|
|
public void Login()
|
|
{
|
|
AvatarSelection();
|
|
}
|
|
public async void AvatarSelection()
|
|
{
|
|
GameObject prefab = await LoadRes.Instance.LoadAssetAsync<GameObject>("ui_common", "选取头像.prefab");
|
|
Instantiate(prefab, transform);
|
|
}
|
|
public void Register()
|
|
{
|
|
|
|
}
|
|
|
|
public void Logout()
|
|
{
|
|
FireBaseCtrl.Instance.Logout();
|
|
}
|
|
|
|
void CheckLoginAndNavigate()
|
|
{
|
|
var status = FireBaseCtrl.Instance.GetDetailedLoginStatus();
|
|
|
|
switch (status.State)
|
|
{
|
|
case FireBaseCtrl.LoginState.LoggedIn:
|
|
pendingUIUpdates.Add(() =>
|
|
{
|
|
info.text ="已登录"+status.UserId;
|
|
});
|
|
break;
|
|
|
|
case FireBaseCtrl.LoginState.NotLoggedIn:
|
|
pendingUIUpdates.Add(() =>
|
|
{
|
|
info.text ="未登录";
|
|
});
|
|
break;
|
|
|
|
case FireBaseCtrl.LoginState.NetworkError:
|
|
pendingUIUpdates.Add(() =>
|
|
{
|
|
info.text ="网络错误";
|
|
});
|
|
break;
|
|
|
|
case FireBaseCtrl.LoginState.Initializing:
|
|
pendingUIUpdates.Add(() =>
|
|
{
|
|
info.text ="正在初始化";
|
|
});
|
|
// 可以设置定时器定期检查状态
|
|
break;
|
|
|
|
default:
|
|
pendingUIUpdates.Add(() =>
|
|
{
|
|
info.text ="未知错误";
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |