Files
FutureMen2/Assets/_FutureMen2/Scripts/UI/LoginPanel.cs
2026-03-30 14:54:03 +08:00

162 lines
4.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.Collections.Generic;
using BestHTTP;
using DragonLi.Core;
using TMPro;
using Unity.XR.PXR;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 登录信息
/// </summary>
public class LoginInfo
{
public string deviceSn = "";
public string startAt = "";
public int shop;
public int gameId;
}
public class ResponseInfo
{
public int code = 400;
public string msg = "";
}
public class LoginPanel : MonoBehaviour
{
public UIState PanelState;
private int RequestLoginCount = 0;
public Image progressImage;
public TextMeshProUGUI progressText;
private int _progress;
private bool _isLogin;
public static void Show()
{
WorldUIManager.Ins.Cover("UI/LoginPanel", false);
}
public void Start()
{
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
#endif
Author();
if (progressImage == null)
return;
StartCoroutine(Progress());
}
public void Author()
{
//延迟请求
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
{
// 登录
GameManager.Ins.Request((req, response) =>
{
RequestLoginCount++;
if (response == null)
{
Debug.Log("鉴权失败1");
if (RequestLoginCount < 2)
{
Author();
return;
}
PanelState.StateChange(1);
return;
}
ResponseInfo info = JsonUtility.FromJson<ResponseInfo>(response.DataAsText);
if (info.code < 200 || info.code >= 300)
{
Debug.Log("鉴权失败2");
if (RequestLoginCount < 2)
{
Author();
return;
}
PanelState.StateChange(1);
return;
}
if (info.code == 200)
{
GameManager.Ins.InitData();
_isLogin = true;
}
});
}, 1);
}
IEnumerator Progress()
{
progressImage.fillAmount = 0;
progressText.text = "0%";
_progress = 0;
_isLogin = false;
GameManager.Ins.InitData();
//_isLogin = true;//修改为本地游戏
float curWaitTime = 0;
while (_progress<=90)
{
//Debug.Log(_progress);
progressText.text = _progress + "%";
progressImage.fillAmount = _progress/100f;
_progress += 1;
yield return new WaitForSeconds(0.02f);
}
Debug.Log("是否鉴定成功 "+_isLogin);
if (_isLogin)
{
while (_progress<=100)
{
progressText.text = _progress + "%";
progressImage.fillAmount = _progress/100f;
_progress += 1;
yield return new WaitForSeconds(0.02f);
}
Debug.Log("鉴权成功");
StartGame();
}
else
{
while (!_isLogin && curWaitTime < 30)
{
curWaitTime += 1;
yield return new WaitForSeconds(1f);
}
if (_isLogin)
{
while (_progress<=100)
{
progressText.text = _progress + "%";
progressImage.fillAmount = _progress/100f;
_progress += 1;
yield return new WaitForSeconds(0.02f);
}
StartGame();
}
}
}
public void StartGame()
{
RequestLoginCount = 0;
WorldUIManager.Ins.Back();
GameManager.Ins.CreateGameStartPoint();
}
}