61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using TMPro;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.AddressableAssets.ResourceLocators;
|
||
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
|
||
|
|
public class UI_VersionUpdate : MonoBehaviour
|
||
|
|
{
|
||
|
|
private Slider _slider;
|
||
|
|
private TMP_Text _textProgress;
|
||
|
|
private AsyncOperationHandle _asyncOperation;
|
||
|
|
|
||
|
|
private void Awake()
|
||
|
|
{
|
||
|
|
_slider = transform.Find("Slider").GetComponent<Slider>();
|
||
|
|
_textProgress = transform.Find("Text_progress").GetComponent<TMP_Text>();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void SetParams(AsyncOperationHandle op)
|
||
|
|
{
|
||
|
|
_asyncOperation = op;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void Update()
|
||
|
|
{
|
||
|
|
Refresh();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void Refresh()
|
||
|
|
{
|
||
|
|
if (_asyncOperation.IsValid())
|
||
|
|
{
|
||
|
|
var downloadStatus = _asyncOperation.GetDownloadStatus();
|
||
|
|
_textProgress.text = $"{string.Format("{0:F1}", downloadStatus.Percent * 100)}% {ConvertBytes(downloadStatus.DownloadedBytes)}/{ConvertBytes(downloadStatus.TotalBytes)}";
|
||
|
|
_slider.value = downloadStatus.Percent;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private string ConvertBytes(long bytes)
|
||
|
|
{
|
||
|
|
if (bytes < 1024)
|
||
|
|
{
|
||
|
|
return $"{bytes}B";
|
||
|
|
}
|
||
|
|
else if (bytes < 1024 * 1024)
|
||
|
|
{
|
||
|
|
return string.Format("{0:f1}KB", bytes / 1024f);
|
||
|
|
}
|
||
|
|
else if (bytes < 1024 * 1024 * 1024)
|
||
|
|
{
|
||
|
|
return string.Format("{0:f1}MB", bytes / (1024f * 1024f));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
return string.Format("{0:f1}GB", bytes / (1024f * 1024f * 1024f));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|