Scene 로딩 방식 변경
This commit is contained in:
parent
365ac96de6
commit
ac3f1a4b9b
@ -76,9 +76,9 @@ public static async Task<List<T>> LoadAssetsByLabel<T>(string label) where T : U
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
public static async Task<SceneInstance> LoadScene(AssetReference assetReference, LoadSceneMode mode = LoadSceneMode.Additive)
|
||||
public static async Task<SceneInstance> 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)
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user