70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_LoadingPanel : BasePanel
|
|
{
|
|
public Slider loadSlider;
|
|
|
|
private float currentProgress = 0;
|
|
public float speed;
|
|
public bool isLoading = false;
|
|
public TextMeshProUGUI Slider_Text;
|
|
public Sprite[] frames; // 将每一帧的Sprite图片依次拖入这个数组中
|
|
public float frameRate = 30f; // 每秒播放的帧数
|
|
private Image image;
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
loadSlider = GetControl<Slider>("loadSlider");
|
|
Slider_Text = GetControl<TextMeshProUGUI>("%");
|
|
image = GetControl<Image>("middleImage");
|
|
}
|
|
|
|
public override void ShowMe()
|
|
{
|
|
base.ShowMe();
|
|
Slider_Text.text = "0%";
|
|
Bootstrap.Instance.eventCenter.AddEventListener<float>(Enum_EventType.UpdateProgress, UpdateProgress);
|
|
|
|
}
|
|
|
|
public override void HideMe()
|
|
{
|
|
base.HideMe();
|
|
loadSlider.value = 0;
|
|
currentProgress = 0;
|
|
speed = 0;
|
|
Bootstrap.Instance.eventCenter.RemoveEventListener<float>(Enum_EventType.UpdateProgress, UpdateProgress);
|
|
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isLoading)
|
|
{
|
|
if (currentProgress < 0.98f)
|
|
{
|
|
currentProgress += Time.deltaTime * speed;
|
|
loadSlider.value = currentProgress;
|
|
float percent = loadSlider.value * 100f;
|
|
Slider_Text.text = Mathf.RoundToInt(percent) + "%";
|
|
}
|
|
else
|
|
{
|
|
isLoading = false;
|
|
HideMe();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateProgress(float speed)
|
|
{
|
|
isLoading = true;
|
|
this.speed = speed;
|
|
}
|
|
}
|
|
|