forked from zxl/Frame
1
0
Fork 0
Frame/Assets/Scripts/UILoading.cs

52 lines
1.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using Game;
using UnityEngine;
using UnityEngine.UI;
public class UILoading : MonoBehaviour
{
[SerializeField]
private Slider _slider;
private bool isFinish;
// Start is called before the first frame update
void Start()
{
EventManager.Instance.Subscribe(LoadingGameSceneFinishEventArgs.EventId, LoadingGameSceneFinishEvent);
this._slider.maxValue = 100;
isFinish = false;
UniTask.Create(this.WaitFinishAsync);
}
private async UniTask WaitFinishAsync()
{
// Debug.Log("开始循环等待");
while (!isFinish)
{
await UniTask.Yield();
// Debug.Log("循环等待");
var f = this._slider.maxValue-this._slider.value;
this._slider .value += f;
}
// Debug.Log("循环等待完成");
this._slider.value = this._slider.maxValue;
await UniTask.Delay(500);
GameObject.DestroyImmediate(this.gameObject);
}
private void LoadingGameSceneFinishEvent(object sender, GameEventArgs e)
{
var args = e as LoadingGameSceneFinishEventArgs;
isFinish = args.IsFinish;
}
private void OnDestroy()
{
EventManager.Instance.Unsubscribe(LoadingGameSceneFinishEventArgs.EventId, LoadingGameSceneFinishEvent);
}
}