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()를 활용해야함
'Unity&C# > Unity' 카테고리의 다른 글
[Unity] Monobehaviour를 상속받지 않은 클래스에서 Coroutine 실행하기 (0) | 2024.10.20 |
---|---|
[Unity] OvelapSphere (0) | 2024.10.17 |
[Unity] Input system - multitap value issue (0) | 2024.10.15 |
[Unity 2D] Sprite Flip (0) | 2024.10.14 |
[Unity] Frame (0) | 2024.10.14 |