39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
// using System
|
|
using UnityEngine;
|
|
|
|
public class ResourceManager {
|
|
public T Load<T>(string path) where T : Object
|
|
{
|
|
return Resources.Load<T>(path);
|
|
}
|
|
|
|
public GameObject Instantiate(string path, Transform parent = null)
|
|
{
|
|
// [PM]_1. 이 original도 들고 있을 경우에는 로드 없이 사용하면 될 것 같다.
|
|
GameObject prefab = Load<GameObject>($"Prefabs/{path}");
|
|
if (prefab == null)
|
|
{
|
|
Debug.Log($"Prefab Missing! {path}");
|
|
return null;
|
|
}
|
|
|
|
// [PM]_2. 혹시 풀링된 오브젝트가 있을 경우에는 그걸 사용하면 된다.
|
|
// 여기는 프리팹을 만들다 보면 뒤에 (Clone) 이라는 이름이 붙는다.
|
|
// 이걸 제거하는 작업
|
|
GameObject go = Object.Instantiate(prefab, parent);
|
|
int idx = go.name.IndexOf("(Clone)");
|
|
if (idx > 0)
|
|
go.name = prefab.name;//go.name.Substring(0, idx);
|
|
return go;
|
|
|
|
// return Object.Instantiate(prefab, parent);
|
|
}
|
|
|
|
public void Destroy(GameObject go)
|
|
{
|
|
if(go == null) return;
|
|
// 만약 풀링 필요시 풀링 매니저에게 위탁
|
|
Object.Destroy(go);
|
|
}
|
|
}
|