79 lines
1.8 KiB
C#
79 lines
1.8 KiB
C#
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+"%";
|
||
}
|
||
}
|
||
}
|