using Cysharp.Threading.Tasks; using System; 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; // 每秒播放的帧数 //public Animator Loadinganimator; //public float speedMultiplier = 5f; private Image image; public int index = 0; protected override void Awake() { base.Awake(); loadSlider = GetControl("loadSlider"); Slider_Text = GetControl("%"); image = GetControl("middleImage"); // 循环播放 //Loadinganimator.speed = speedMultiplier; //Loadinganimator.Play("合成 1_00000"); } public override void ShowMe() { base.ShowMe(); // 循环播放 index = 0; Slider_Text.text = "0%"; Bootstrap.Instance.eventCenter.AddEventListener(Enum_EventType.UpdateProgress, UpdateProgress); } public override void HideMe() { base.HideMe(); loadSlider.value = 0; currentProgress = 0; speed = 0; Bootstrap.Instance.eventCenter.RemoveEventListener(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(); } } } public async UniTask Loading() { while (isLoading) { index++; Debug.Log(index+"啊啊啊啊啊啊啊啊啊"); await UniTask.Delay(10); if (index >= frames.Length) { index = 0; } image.sprite = frames[index]; } } private async void UpdateProgress(float speed) { isLoading = true; this.speed = speed; await Loading(); } //private IEnumerator Animate() //{ // for (int i = 0; i < frames.Length; i++) // { // image.sprite = frames[i]; // yield return new WaitForSeconds(1f / frameRate); // } //} }