Project_WL/Assets/Script/UI/ETC/LoadingUI.cs

67 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
using Random = UnityEngine.Random;
public class LoadingUI : MyCoroutine
{
public static LoadingUI Ins;
public GameObject go;
public TextMeshProUGUI[] texts; // 0 팁, 1 로딩 진행 상황
public Slider slider_loading;
public RawImage loadingimg;
AsyncOperationHandle<Texture> currentHandle;
List<bool> list_loadingComplete = new List<bool> { false, false };
public int MaxImage = 1;
int m_index = 1;
void Awake() { Ins = this; }
public void Start_Loading()
{
go.SetActive(true);
m_index = Random.Range(1, MaxImage + 1);
texts[0].text = "팁 입니다.";
slider_loading.value = 0f;
texts[1].text = "0%";
AddrResourceMgr.Ins.LoadObject<Texture>($"Assets/Res_Addr/Loading/Loading{m_index}.jpg", handle =>
{
if (currentHandle.IsValid())
{
Addressables.Release(currentHandle);
loadingimg.texture = null; // 기존 Texture 참조 해제
}
currentHandle = handle;
loadingimg.enabled = true;
loadingimg.texture = handle.Result;
});
for (int i = 0; i < list_loadingComplete.Count; i++)
list_loadingComplete[i] = false;
}
public void Set_LoadingSlider(float proc)
{
slider_loading.value = proc;
texts[1].text = $"{proc * 100f:N0}%";
}
public void End_Loading(int index)
{
list_loadingComplete[index] = true;
bool endloading = true;
for (int i = 0; i < list_loadingComplete.Count; i++)
{
endloading = list_loadingComplete[i];
if (!endloading) break;
}
if (endloading) go.SetActive(false);
}
}