104 lines
3.0 KiB
C#
104 lines
3.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_LoginPanel : BasePanel
|
|
{
|
|
public static UI_LoginPanel instance;
|
|
public TextMeshProUGUI dayText; //日期文本
|
|
public TextMeshProUGUI TimeText; //时间文本
|
|
|
|
public TMP_InputField inputAccount;
|
|
public TMP_InputField inputPassword;
|
|
|
|
public GameObject TipPanel; //账号密码输入错误弹框
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
instance = this;
|
|
OnInit();
|
|
}
|
|
|
|
public void OnInit()
|
|
{
|
|
dayText = GetControl<TextMeshProUGUI>("日期");
|
|
TimeText = GetControl<TextMeshProUGUI>("时间");
|
|
inputAccount = GetControl<TMP_InputField>("账号输入框");
|
|
inputPassword = GetControl<TMP_InputField>("密码输入框");
|
|
TipPanel.SetActive(false);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
DateTime now = DateTime.Now;
|
|
dayText.text = now.ToString("yyyy-MM-dd");
|
|
TimeText.text = now.ToString("HH:mm:ss");
|
|
}
|
|
|
|
public override void ShowMe()
|
|
{
|
|
base.ShowMe();
|
|
}
|
|
|
|
public override void HideMe()
|
|
{
|
|
base.HideMe();
|
|
}
|
|
|
|
protected override void OnClick(string btnPath)
|
|
{
|
|
base.OnClick(btnPath);
|
|
switch (btnPath)
|
|
{
|
|
case "登录按钮":
|
|
Debug.Log("登录");
|
|
|
|
string account = inputAccount.text;
|
|
string password = inputPassword.text;
|
|
|
|
// 设置登录成功后的回调
|
|
LoginManager.Instance.OnLoginSuccess = () =>
|
|
{
|
|
Debug.Log("登录验证成功,开始切换场景...");
|
|
Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "ChooesSubjectScene", () =>
|
|
{
|
|
Bootstrap.Instance.uiManager.ShowPanel<UI_ChooesPanel>(this, E_UI_Layer.Mid, (panel) =>
|
|
{
|
|
Bootstrap.Instance.uiManager.ShowPanel<UI_TopTitlePanel>(this, E_UI_Layer.Top, (panel) =>
|
|
{
|
|
Bootstrap.Instance.uiManager.HidePanel<UI_LoginPanel>();
|
|
Debug.Log("场景加载成功");
|
|
});
|
|
});
|
|
}
|
|
);
|
|
};
|
|
|
|
// 发起登录请求
|
|
LoginManager.Instance.Login(account, password);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示提示文本并自动隐藏
|
|
/// </summary>
|
|
public void ShowTip(string msg, float duration = 2f)
|
|
{
|
|
StopAllCoroutines();
|
|
StartCoroutine(ShowTipCoroutine(msg, duration));
|
|
}
|
|
|
|
IEnumerator ShowTipCoroutine(string msg, float duration)
|
|
{
|
|
TextMeshProUGUI tipText = TipPanel.GetComponentInChildren<TextMeshProUGUI>();
|
|
tipText.text = msg;
|
|
TipPanel.gameObject.SetActive(true);
|
|
yield return new WaitForSeconds(duration);
|
|
TipPanel.gameObject.SetActive(false);
|
|
}
|
|
} |