killapp/Assets/Scripts/UI/Components/UpdateLoadingUI.cs

79 lines
1.8 KiB
C#
Raw Permalink Normal View History

2026-06-08 08:55:10 +08:00
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;
2026-06-12 16:07:27 +08:00
precent.text=0+"%";
2026-06-08 08:55:10 +08:00
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}%");
2026-06-12 16:07:27 +08:00
precent.text=(int)progress.ProgressPercentage+"%";
2026-06-08 08:55:10 +08:00
}
public void SetPrecent(float p)
{
int fullP=(int)(p*100);
precent.text=fullP+"%";
}
}
}