using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class Sandbox : MonoBehaviour
{
public Image imageComponent;
private HyperX.Http.FileDownloadProgress fileDownloadProgress;
async void Start()
{
string fileName = "hyperx.png";
string downloadPath = "/AdditionalAssets/hyperx.png";
string serverHash = await HyperX.Core.PublicStorage.GetHash(fileName);
string localHash = PlayerPrefs.GetString($"DOWNLOADED_FILE_HASH:{fileName}");
if (serverHash == localHash)
{
Debug.Log("이미 최신 파일이 다운로드 되어있습니다.");
}
else
{
Debug.Log("파일 다운로드를 시작합니다.");
fileDownloadProgress = HyperX.Core.PublicStorage.Get("hyperx.png", downloadPath);
await fileDownloadProgress.File;
PlayerPrefs.SetString($"DOWNLOADED_FILE_HASH:{fileName}", serverHash);
Debug.Log("파일 다운로드가 완료되었습니다.");
}
byte[] imageByte = File.ReadAllBytes(Application.persistentDataPath + downloadPath);
Texture2D texture = new Texture2D(200, 200);
texture.LoadImage(imageByte);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
imageComponent.sprite = sprite;
}
void Update()
{
if (
fileDownloadProgress != null
&& fileDownloadProgress.Status == HyperX.Http.FileDownloadStatus.IN_PROGRESS
)
{
Debug.Log($"파일 다운로드 진행 상태: {fileDownloadProgress.Progress}%");
}
}
}