Unity - ResourceManager

이승덱·2021년 12월 25일
0

UnityEngine

목록 보기
6/11

Unity - ResoureceManager

  • ResourceManager는 Prefab을 동적으로 생성하고자 할 때 각 클래스에서 생성하기 보단 하나의 클래스를 통해서만 생성하도록 하여 관리를 하기 위해 구현한다.
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)
    {
        GameObject prefab = Load<GameObject>($"Prefabs/{path}");

        if(prefab == null)
        {
            Debug.Log($"Failed to load prefab : {path}");
        }
        return Object.Instantiate(prefab,parent);
    }

    public void Destroy(GameObject go)
    {
        if (go == null)
            return;
        Object.Destroy(go);
    }
}
  • 이런 식으로 ResourceManager를 사용하면 Resource 관련 로그 처리를 간편하게 할 수 있다.
profile
공부 기록용 블로그입니다

0개의 댓글