From f98507fe9f0018edb946b5948c65a592dd840393 Mon Sep 17 00:00:00 2001 From: NTG_Lenovo Date: Thu, 3 Jul 2025 13:18:16 +0900 Subject: [PATCH] =?UTF-8?q?Scene=20=EA=B4=80=EB=A6=AC=20Dictionary=20->=20?= =?UTF-8?q?=ED=99=95=EC=9E=A5=20=EB=A9=94=EC=84=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../02.Scripts/Controllers/GameManager.cs | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Assets/_Datas/02.Scripts/Controllers/GameManager.cs b/Assets/_Datas/02.Scripts/Controllers/GameManager.cs index 1e7cd89a7..e36ea9f1c 100644 --- a/Assets/_Datas/02.Scripts/Controllers/GameManager.cs +++ b/Assets/_Datas/02.Scripts/Controllers/GameManager.cs @@ -13,14 +13,21 @@ public enum SceneType Restaurant = 1 } + public static class SceneTypeExtensions + { + public static string ToSceneName(this SceneType sceneType) + { + return sceneType switch + { + SceneType.Title => "00.Title", + SceneType.Restaurant => "01.Restaurant", + _ => throw new ArgumentOutOfRangeException(nameof(sceneType), sceneType, null) + }; + } + } + public class GameManager : Singleton { - private static readonly Dictionary SceneTypeDict = new() - { - { SceneType.Title, "00.Title" }, - { SceneType.Restaurant, "01.Restaurant" } - }; - public SceneType CurrentSceneType { get; private set; } private void Start() @@ -30,9 +37,15 @@ private void Start() public async Task ChangeScene(SceneType sceneType) { - if (!SceneTypeDict.TryGetValue(sceneType, out string changeSceneName)) + string changeSceneName; + + try { - Debug.LogError($"[GameManager] 정의되지 않은 SceneType: {sceneType}"); + changeSceneName = sceneType.ToSceneName(); + } + catch (ArgumentOutOfRangeException e) + { + Debug.LogError($"[GameManager] 정의되지 않은 SceneType: {sceneType} - {e.Message}"); return; } @@ -57,8 +70,8 @@ public async Task ChangeScene(SceneType sceneType) public void ChangeSceneByIndex(int index) { - var sceneEnum = (SceneType)index; - _ = ChangeScene(sceneEnum); + var sceneType = (SceneType)index; + _ = ChangeScene(sceneType); } } } \ No newline at end of file