diff --git a/Assets/_DDD/_Scripts/GameFramework/GameManager.cs b/Assets/_DDD/_Scripts/GameFramework/GameManager.cs index bc7692cd5..ffe6dc34b 100644 --- a/Assets/_DDD/_Scripts/GameFramework/GameManager.cs +++ b/Assets/_DDD/_Scripts/GameFramework/GameManager.cs @@ -11,7 +11,7 @@ public class GameManager : Singleton private List _managerInstances; - protected async void Start() + protected override void OnAwake() { base.OnAwake(); @@ -22,38 +22,29 @@ protected async void Start() private async Task Initialize() { - if (_managerDefinitionSo == null) - { - Debug.LogError("_managerDefinitionSo"); - return; - } + Debug.Assert(_managerDefinitionSo != null, "_managerDefinitionSo is null"); _managerInstances = new List(_managerDefinitionSo.ManagerClasses.Count); - // 매니저 클래스들을 순회하면서 씬에 존재하는지 확인하고 생성 또는 재사용 foreach (var managerPrefab in _managerDefinitionSo.ManagerClasses) { if (managerPrefab == null) { - Debug.LogWarning("매니저 프리팹이 null입니다. 건너뜁니다."); + Debug.LogWarning($"{managerPrefab.name} 프리팹이 null입니다. 건너뜁니다."); continue; } - // 씬에 이미 해당 타입의 매니저가 존재하는지 확인 - var existingManager = FindObjectOfType(managerPrefab.GetType()) as Singleton; - + var existingManager = FindAnyObjectByType(managerPrefab.GetType()) as Singleton; + if (existingManager != null) { - // 이미 씬에 존재하는 경우 재사용 - Debug.Log($"매니저 {managerPrefab.GetType().Name}이(가) 씬에 이미 존재합니다. 재사용합니다."); + print($"{existingManager.name} 오브젝트가 이미 존재합니다."); _managerInstances.Add(existingManager); } else { - // 씬에 존재하지 않는 경우 새로 생성 var newManagerInstance = Instantiate(managerPrefab); - newManagerInstance.name = $"{managerPrefab.name}_Instance"; - Debug.Log($"매니저 {managerPrefab.GetType().Name}을(를) 새로 생성했습니다."); + newManagerInstance.name = managerPrefab.name; _managerInstances.Add(newManagerInstance); } } diff --git a/Assets/_DDD/_Scripts/Utilities/Singletone.cs b/Assets/_DDD/_Scripts/Utilities/Singletone.cs index 00c3cabeb..1b2082da5 100644 --- a/Assets/_DDD/_Scripts/Utilities/Singletone.cs +++ b/Assets/_DDD/_Scripts/Utilities/Singletone.cs @@ -76,6 +76,7 @@ protected virtual void Awake() else if (_instance != this) { Destroy(gameObject); + return; } } OnAwake();