Project_WL/Assets/Script/Util/UI3DModel.cs

60 lines
2.1 KiB
C#
Raw Normal View History

2024-12-15 01:39:39 +00:00
using System;
using UnityEngine;
2025-02-17 22:30:54 +00:00
using UnityEngine.AddressableAssets;
2024-12-15 01:39:39 +00:00
using UnityEngine.AI;
2025-02-17 22:30:54 +00:00
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
2024-12-15 01:39:39 +00:00
public class UI3DModel : MonoBehaviour
{
2025-02-17 22:30:54 +00:00
public RawImage RawImage_costume;
2024-12-15 01:39:39 +00:00
public Transform tf_model;
2025-02-17 22:30:54 +00:00
AsyncOperationHandle<Texture> currentHandle;
2025-02-18 05:59:11 +00:00
AsyncOperationHandle<GameObject> GoHandle;
2025-02-17 22:30:54 +00:00
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;
});
}
}
2025-02-17 23:53:54 +00:00
protected void Set_3DModel(bool pc, string prefab, Action<Transform> act = null)
2024-12-15 01:39:39 +00:00
{
2025-04-09 23:32:26 +00:00
for (int i = 1; i < tf_model.childCount; i++) // 0 은 빛
2024-12-15 01:39:39 +00:00
Destroy(tf_model.GetChild(i).gameObject);
2025-02-17 23:53:54 +00:00
var path = pc ? $"Assets/Res_Addr/PC/{prefab}.prefab" : prefab;
AddrResourceMgr.Ins.LoadObject<GameObject>(path, handle =>
2024-12-15 01:39:39 +00:00
{
2025-02-18 05:59:11 +00:00
if (GoHandle.IsValid())
Addressables.Release(GoHandle);
GoHandle = handle;
var go = DSUtil.Get_Clone(GoHandle.Result, tf_model);
2024-12-15 01:39:39 +00:00
if (DSUtil.CheckNull(go.GetComponent<AddressableReleaseSelf>()))
go.AddComponent<AddressableReleaseSelf>();
DSUtil.ChangeLayersRecursively(go.transform, "UI");
go.GetComponent<Actor>().Stop(true);
2025-02-18 05:59:11 +00:00
if (pc) go.GetComponent<PCActor>().Set_UIPC();
2024-12-15 01:39:39 +00:00
Destroy(go.GetComponent<BoxCollider>());
Destroy(go.GetComponent<NavMeshAgent>());
Destroy(go.GetComponent<Rigidbody>());
act?.Invoke(go.transform);
});
}
}