killapp/Assets/Scripts/UI/Components/UpdateLoadingUI.cs
“虞渠成” 696b508187 debug
2026-06-12 16:07:27 +08:00

79 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Kill.Network;
using UnityEngine;
using UnityEngine.UI;
namespace Kill.UI.Components
{
/// <summary>
/// 全局Loading组件
/// 调用 LoadingUI.Show() 显示LoadingUI.Hide() 隐藏
/// </summary>
public class UpdateLoadingUI : MonoBehaviour
{
public static UpdateLoadingUI Instance { get; private set; }
[Header("UI引用")]
public GameObject loadingPanel;
public PlayFlash loadingAni;
public Text precent;
private void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
private void Start()
{
Hide();
}
/// <summary>
/// 显示Loading
/// </summary>
public void Show()
{
if (Instance == null) return;
precent.text=0+"%";
Instance.loadingPanel.SetActive(true);
if (Instance.loadingAni != null)
loadingAni.Play();
}
/// <summary>
/// 隐藏Loading
/// </summary>
public void Hide()
{
if (Instance == null) return;
if (Instance.loadingAni != null)
Instance.loadingAni.Stop();
Instance.loadingPanel.SetActive(false);
}
public void GetDownloadProcess(DownloadProgress progress)
{
Debug.Log($"下载进度: {progress.ProgressPercentage}%");
precent.text=(int)progress.ProgressPercentage+"%";
}
public void SetPrecent(float p)
{
int fullP=(int)(p*100);
precent.text=fullP+"%";
}
}
}