Project_WL/Assets/Script/Util/UI3DModel.cs

60 lines
2.1 KiB
C#

using System;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.AI;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
public class UI3DModel : MonoBehaviour
{
public RawImage RawImage_costume;
public Transform tf_model;
AsyncOperationHandle<Texture> currentHandle;
AsyncOperationHandle<GameObject> GoHandle;
protected void Set_2DIlust(CostumeListTableData costumeData)
{
if (!DSUtil.CheckNull(costumeData))
{
AddrResourceMgr.Ins.LoadObject<Texture>($"Assets/Res_Addr/PCCostumeImage/{costumeData.s_Image}.png", handle =>
{
if (currentHandle.IsValid())
{
Addressables.Release(currentHandle);
RawImage_costume.texture = null; // 기존 Texture 참조 해제
}
currentHandle = handle;
RawImage_costume.enabled = true;
RawImage_costume.texture = handle.Result;
});
}
}
protected void Set_3DModel(bool pc, string prefab, Action<Transform> act = null)
{
for (int i = 1; i < tf_model.childCount; i++) // 0 은 빛
Destroy(tf_model.GetChild(i).gameObject);
var path = pc ? $"Assets/Res_Addr/PC/{prefab}.prefab" : prefab;
AddrResourceMgr.Ins.LoadObject<GameObject>(path, handle =>
{
if (GoHandle.IsValid())
Addressables.Release(GoHandle);
GoHandle = handle;
var go = DSUtil.Get_Clone(GoHandle.Result, tf_model);
if (DSUtil.CheckNull(go.GetComponent<AddressableReleaseSelf>()))
go.AddComponent<AddressableReleaseSelf>();
DSUtil.ChangeLayersRecursively(go.transform, "UI");
go.GetComponent<Actor>().Stop(true);
if (pc) go.GetComponent<PCActor>().Set_UIPC();
Destroy(go.GetComponent<BoxCollider>());
Destroy(go.GetComponent<NavMeshAgent>());
Destroy(go.GetComponent<Rigidbody>());
act?.Invoke(go.transform);
});
}
}