using TMPro; using UnityEngine; using UnityEngine.UI; public class BoostrapLoading : MonoBehaviour { [SerializeField] private TMP_Text loadingInfo; [SerializeField] private TMP_Text versionInfo; [SerializeField] private Image progressBar; [SerializeField] private Image subProgressBar; [SerializeField] private TMP_Text ProgressLabel; [SerializeField] private TMP_Text DownloadSize; public void Show() { gameObject.SetActive(true); } public void Hide() { gameObject.SetActive(false); } public void SetVersionInfo(string verStr) { versionInfo.text = verStr; } public void SetProgress(float progress) { progressBar.fillAmount = progress; var percent_text = (progress * 100f); ProgressLabel.text = $"{percent_text.ToString("0.00")}%"; //bool visible = progress != 0; bool visible = progress >= 0; progressBar.transform.parent.gameObject.SetActive(visible); ProgressLabel.gameObject.SetActive(visible); } private const double byte2mb = 1024 * 1024; public void SetProgress(float progress, long downloadBytes, long totalBytes) { bool visible = progress >= 0; progressBar.transform.parent.gameObject.SetActive(visible); ProgressLabel.gameObject.SetActive(visible); if(visible) { progressBar.fillAmount = progress; var progressStr = $"{(downloadBytes/byte2mb).ToString("0.00")}MB/{(totalBytes/byte2mb).ToString("0.00")}MB ({(progress * 100f).ToString("0.00")}%)"; ProgressLabel.text = progressStr; } } public void SetSubProgress(float progress) { bool visible = progress >= 0; subProgressBar.gameObject.SetActive(visible); if(visible) { subProgressBar.fillAmount = progress; } } public void SetDownloadSize(long downloadBytes, long totalBytes) { if(downloadBytes <0 || downloadBytes == totalBytes) DownloadSize.text = string.Empty; else DownloadSize.text = $"{(downloadBytes/byte2mb).ToString("0.0")}MB/{(totalBytes/byte2mb).ToString("0.0")}MB"; } public void SetInfo(string info) { loadingInfo.text = info; } }