From 6df9f4cfae9a5b759b68a95a0b8f315f72b5c9df Mon Sep 17 00:00:00 2001 From: NTG Date: Thu, 14 Aug 2025 17:01:55 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8B=B1=EA=B8=80=ED=86=A4,=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=EB=A7=A4=EB=8B=88=EC=A0=80=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 싱글톤이 파괴되기전에 OnAwake를 호출하는 오류 수정 2. 게임매니저 로직 start -> awake로 변경 --- .../_Scripts/GameFramework/GameManager.cs | 23 ++++++------------- Assets/_DDD/_Scripts/Utilities/Singletone.cs | 1 + 2 files changed, 8 insertions(+), 16 deletions(-) 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();