Resources.UnloadAsset()
- 로드된 에셋을 언로드 하는 메소드
- 이미 인스턴스화된 게임 오브젝트에는 영향을 미치지 않음.
public class UIManager
{
private Dictionary<string,GameObject> _cache;
// 싱글톤 초기화
public void OpenPopupUI(string path)
{
if(!_cache.ContainKey(path))
{
_cache.add(string,GameManager.Instantiate(Resources.Load<GameObject>($"Prefabs/{path}"));
}
/*캐쉬에서 object를 꺼내서 intantiate시키는 코드*/
}
public void ClearCache()
{
foreach(var key in _cache.getkeys)
{
Resources.UnloadAsset(_cache[key]);
}
}
}
- 이렇게 Instantiate한 GameObject를 Unload하는 것은 안됨.
- 이는 Destroy()를 활용해야함