From ac3f1a4b9bb28318cd3f83809075e507d0887a92 Mon Sep 17 00:00:00 2001 From: NTG Date: Tue, 19 Aug 2025 18:24:36 +0900 Subject: [PATCH] =?UTF-8?q?Scene=20=EB=A1=9C=EB=94=A9=20=EB=B0=A9=EC=8B=9D?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_Scripts/AssetManagement/AssetManager.cs | 4 +- .../GameFramework/Scene/SceneManager.cs | 90 +++++++------------ 2 files changed, 33 insertions(+), 61 deletions(-) diff --git a/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs b/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs index 8f06ed425..d1ab863b7 100644 --- a/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs +++ b/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs @@ -76,9 +76,9 @@ public static async Task> LoadAssetsByLabel(string label) where T : U return new List(); } - public static async Task LoadScene(AssetReference assetReference, LoadSceneMode mode = LoadSceneMode.Additive) + public static async Task LoadScene(AssetReference assetReference, LoadSceneMode mode = LoadSceneMode.Additive, bool activateOnLoad = true) { - var handle = Addressables.LoadSceneAsync(assetReference, mode); + var handle = Addressables.LoadSceneAsync(assetReference, mode, activateOnLoad); await handle.Task; if (handle.Status == AsyncOperationStatus.Succeeded) diff --git a/Assets/_DDD/_Scripts/GameFramework/Scene/SceneManager.cs b/Assets/_DDD/_Scripts/GameFramework/Scene/SceneManager.cs index 0bcfca570..87a4f38ef 100644 --- a/Assets/_DDD/_Scripts/GameFramework/Scene/SceneManager.cs +++ b/Assets/_DDD/_Scripts/GameFramework/Scene/SceneManager.cs @@ -69,6 +69,34 @@ public void PostInit() } + public async Task PreloadAll() + { + var flowToSceneMapping = GameFlowManager.Instance.GameFlowSceneMappingSo.FlowToSceneMapping; + + foreach (var flowAssetPair in flowToSceneMapping) + { + if (_loadedSceneDatas.ContainsKey(flowAssetPair.Key)) continue; + + var runtimeKey = GetRuntimeKey(flowAssetPair.Value); + if (_assetKeyToSceneData.TryGetValue(runtimeKey, out var existing)) + { + _loadedSceneDatas[flowAssetPair.Key] = existing; + continue; + } + + var instance = await AssetManager.LoadScene(flowAssetPair.Value, activateOnLoad:false); + if (!instance.Scene.IsValid()) + { + Debug.LogError($"[SceneManager] {flowAssetPair.Key}의 씬 로딩 실패"); + continue; + } + + var data = new SceneData(instance.Scene, instance); + _loadedSceneDatas[flowAssetPair.Key] = data; + _assetKeyToSceneData[runtimeKey] = data; + } + } + public async Task PreloadScene(GameFlowState gameFlowState) { if (_loadedSceneDatas.ContainsKey(gameFlowState)) return; @@ -93,41 +121,10 @@ public async Task PreloadScene(GameFlowState gameFlowState) return; } - DeactivateScene(loadedInstance.Scene); - var data = new SceneData(loadedInstance.Scene, loadedInstance); _loadedSceneDatas[gameFlowState] = data; _assetKeyToSceneData[runtimeKey] = data; } - - public async Task PreloadAll() - { - var flowToSceneMapping = GameFlowManager.Instance.GameFlowSceneMappingSo.FlowToSceneMapping; - - foreach (var flowAssetPair in flowToSceneMapping) - { - if (_loadedSceneDatas.ContainsKey(flowAssetPair.Key)) continue; - - var runtimeKey = GetRuntimeKey(flowAssetPair.Value); - if (_assetKeyToSceneData.TryGetValue(runtimeKey, out var existing)) - { - _loadedSceneDatas[flowAssetPair.Key] = existing; - continue; - } - - var instance = await AssetManager.LoadScene(flowAssetPair.Value); - if (!instance.Scene.IsValid()) - { - Debug.LogError($"[SceneManager] {flowAssetPair.Key}의 씬 로딩 실패"); - continue; - } - - DeactivateScene(instance.Scene); - var data = new SceneData(instance.Scene, instance); - _loadedSceneDatas[flowAssetPair.Key] = data; - _assetKeyToSceneData[runtimeKey] = data; - } - } public async Task ActivateScene(GameFlowState newFlowState) { @@ -148,19 +145,10 @@ public async Task ActivateScene(GameFlowState newFlowState) { await handler.OnBeforeSceneActivate(); } - - foreach (var root in sceneData.Scene.GetRootGameObjects()) + + if (sceneData.SceneInstance.HasValue) { - root.SetActive(true); - } - - if (sceneData.Scene.IsValid()) - { - UnityEngine.SceneManagement.SceneManager.SetActiveScene(sceneData.Scene); - } - else - { - Debug.LogError($"[SceneManager] {newFlowState}의 Scene이 유효하지 않습니다."); + await sceneData.SceneInstance.Value.ActivateAsync(); } foreach (var handler in _sceneTransitionHandlerSo.Handlers.Where(handler => handler != null)) @@ -169,22 +157,6 @@ public async Task ActivateScene(GameFlowState newFlowState) } } - public void DeactivateScene(GameFlowState gameFlowState) - { - if (_loadedSceneDatas.TryGetValue(gameFlowState, out var sceneData)) - { - DeactivateScene(sceneData.Scene); - } - } - - private void DeactivateScene(Scene scene) - { - foreach (var rootObject in scene.GetRootGameObjects()) - { - rootObject.SetActive(false); - } - } - public async Task UnloadScene(GameFlowState gameFlowState) { if (_loadedSceneDatas.TryGetValue(gameFlowState, out var sceneData))