86 lines
2.5 KiB
C#
86 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
using AsyncOperation = UnityEngine.AsyncOperation;
|
|
|
|
public class LodingPanel : BasePanel
|
|
{
|
|
public RectTransform imgFront;
|
|
public float maxWidth = 850f;
|
|
float progress = 0f;
|
|
|
|
|
|
private bool isFinish = false;
|
|
|
|
public override void Init()
|
|
{
|
|
// 开始加载场景
|
|
StartCoroutine(LoadSceneAsync());
|
|
}
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
UpdateProgress(progress);
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
// 更新进度条
|
|
if (progress < 1f)
|
|
{
|
|
progress += Time.deltaTime * 0.5f;
|
|
UpdateProgress(progress);
|
|
}
|
|
else
|
|
{
|
|
progress = 1f;
|
|
UpdateProgress(progress);
|
|
}
|
|
|
|
if (isFinish&&progress==1)
|
|
{
|
|
UIManager.Instance.HidePanel<LodingPanel>(false);
|
|
UIManager.Instance.ShowPanel<GamePanel>();
|
|
}
|
|
}
|
|
|
|
private IEnumerator LoadSceneAsync()
|
|
{
|
|
//获取微信数据
|
|
GameDataMgr.Instance.loginMsg.openId = "user_openid_1223asasdf";
|
|
GameDataMgr.Instance.loginMsg.username = "player132";
|
|
GameDataMgr.Instance.loginMsg.picUrl = "https://example.com/pic.png";
|
|
yield return StartCoroutine(NetMgr.Instance.PlayerDataPost(GameDataMgr.Instance.loginMsg));
|
|
// 开始异步场景加载
|
|
AsyncOperation operation = SceneManager.LoadSceneAsync("GameScene");
|
|
yield return StartCoroutine(NetMgr.Instance.PlayerTempGet());
|
|
GameDataMgr.Instance.levRankMsg.id = GameDataMgr.Instance.player.customLev;
|
|
if (GameDataMgr.Instance.player.customLev==0)
|
|
{
|
|
GameDataMgr.Instance.levRankMsg.id = 1;
|
|
}
|
|
GameDataMgr.Instance.levRankMsg.openId = GameDataMgr.Instance.player.openId;
|
|
yield return StartCoroutine(NetMgr.Instance.LevPetInfoPost(GameDataMgr.Instance.levRankMsg));
|
|
yield return StartCoroutine(GameMgr.Instance.CreatePetObj());
|
|
isFinish =true;
|
|
}
|
|
private void UpdateProgress(float progress)
|
|
{
|
|
// 更新 Image 的宽度
|
|
float newWidth = maxWidth * progress;
|
|
imgFront.sizeDelta = new Vector2(newWidth, imgFront.sizeDelta.y);
|
|
}
|
|
|
|
// 接收来自 JavaScript 的微信用户信息
|
|
public void ReceiveWeChatInfo(string weChatData)
|
|
{
|
|
GameDataMgr.Instance.loginMsg = JsonUtility.FromJson<LoginMsg>(weChatData);
|
|
}
|
|
|
|
}
|