194 lines
5.3 KiB
C#
194 lines
5.3 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using BestHTTP;
|
||
using DragonLi.Core;
|
||
using Mirror;
|
||
using Mirror.SimpleWeb;
|
||
using TMPro;
|
||
using Unity.XR.PXR;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using XUI;
|
||
|
||
/// <summary>
|
||
/// 鉴权信息
|
||
/// </summary>
|
||
public class AuthInfo
|
||
{
|
||
public string deviceSn = "";
|
||
public string startAt = "";
|
||
public int shop;
|
||
public int gameId;
|
||
}
|
||
|
||
public class ResponseInfo
|
||
{
|
||
public int code = 400;
|
||
public string msg = "";
|
||
}
|
||
|
||
public class ConfInfo
|
||
{
|
||
public string createdAt;
|
||
public string data;
|
||
}
|
||
|
||
public class ConfResponseInfo
|
||
{
|
||
public int status = 400;
|
||
public string message = "";
|
||
public ConfInfo data = new ConfInfo();
|
||
}
|
||
|
||
namespace Common
|
||
{
|
||
public class AuthorPanel : UIBehaviour
|
||
{
|
||
public Common.State PanelState;
|
||
|
||
private int RequestAuthCount = 0;
|
||
|
||
public Image progressImage;
|
||
public TextMeshProUGUI progressText;
|
||
|
||
private int _progress;
|
||
private bool _isAuth;
|
||
public static void Show()
|
||
{
|
||
WorldUIManager.Ins.Cover("UI/AuthorPanel", false);
|
||
}
|
||
|
||
public void Start()
|
||
{
|
||
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
|
||
PXR_Enterprise.InitEnterpriseService();
|
||
PXR_Enterprise.BindEnterpriseService();
|
||
#endif
|
||
Author();
|
||
if (progressImage == null)
|
||
return;
|
||
StartCoroutine(Progress());
|
||
}
|
||
|
||
public void Author()
|
||
{
|
||
|
||
//延迟请求
|
||
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
||
{
|
||
//StartCoroutine(GameManager.Ins.PlayAudio("主界面主题曲", GameInit.Ins.self.transform, true));
|
||
// Debug.Log("鉴权成功");
|
||
// RequestAuthCount = 0;
|
||
// WorldUIManager.Ins.Back();
|
||
// GameManager.Ins.UpdateConf();
|
||
// GameManager.Ins.StartGame();
|
||
// 鉴权
|
||
GameLocal.Ins.RequestAuth((req, response) =>
|
||
{
|
||
RequestAuthCount++;
|
||
if (response == null)
|
||
{
|
||
Debug.Log("鉴权失败1");
|
||
if (RequestAuthCount < 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 (RequestAuthCount < 2)
|
||
{
|
||
Author();
|
||
return;
|
||
}
|
||
PanelState.StateChange(1);
|
||
return;
|
||
}
|
||
|
||
if (info.code == 200)
|
||
{
|
||
Debug.Log("鉴权成功");
|
||
_isAuth = true;
|
||
//GameManager.Ins.CreateMap();
|
||
}
|
||
else if (MRNetworkManager.Ins.mode == NetworkManagerMode.ClientOnly)
|
||
{
|
||
WorldUIManager.Ins.Back();
|
||
}
|
||
});
|
||
}, 1);
|
||
}
|
||
|
||
IEnumerator Progress()
|
||
{
|
||
|
||
progressImage.fillAmount = 0;
|
||
progressText.text = "0%";
|
||
_progress = 0;
|
||
_isAuth = false;
|
||
//_isAuth = 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("是否鉴定成功 :"+_isAuth);
|
||
if (_isAuth)
|
||
{
|
||
while (_progress<=100)
|
||
{
|
||
progressText.text = _progress + "%";
|
||
progressImage.fillAmount = _progress/100f;
|
||
_progress += 1;
|
||
yield return new WaitForSeconds(0.02f);
|
||
}
|
||
|
||
Save();
|
||
}
|
||
else
|
||
{
|
||
while (!_isAuth && curWaitTime < 30)
|
||
{
|
||
curWaitTime += 1;
|
||
yield return new WaitForSeconds(1f);
|
||
}
|
||
if (_isAuth)
|
||
{
|
||
while (_progress<=100)
|
||
{
|
||
progressText.text = _progress + "%";
|
||
progressImage.fillAmount = _progress/100f;
|
||
_progress += 1;
|
||
yield return new WaitForSeconds(0.02f);
|
||
}
|
||
|
||
Save();
|
||
}
|
||
else
|
||
{
|
||
PanelState.StateChange(1);
|
||
}
|
||
}
|
||
}
|
||
|
||
public void Save()
|
||
{
|
||
RequestAuthCount = 0;
|
||
WorldUIManager.Ins.Back();
|
||
ConPanel.Show();
|
||
}
|
||
}
|
||
|
||
}
|