Scene 관리 Dictionary -> 확장 메서드
This commit is contained in:
parent
3d2b794f66
commit
f98507fe9f
@ -13,14 +13,21 @@ public enum SceneType
|
|||||||
Restaurant = 1
|
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<GameManager>
|
public class GameManager : Singleton<GameManager>
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<SceneType, string> SceneTypeDict = new()
|
|
||||||
{
|
|
||||||
{ SceneType.Title, "00.Title" },
|
|
||||||
{ SceneType.Restaurant, "01.Restaurant" }
|
|
||||||
};
|
|
||||||
|
|
||||||
public SceneType CurrentSceneType { get; private set; }
|
public SceneType CurrentSceneType { get; private set; }
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@ -30,9 +37,15 @@ private void Start()
|
|||||||
|
|
||||||
public async Task ChangeScene(SceneType sceneType)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +70,8 @@ public async Task ChangeScene(SceneType sceneType)
|
|||||||
|
|
||||||
public void ChangeSceneByIndex(int index)
|
public void ChangeSceneByIndex(int index)
|
||||||
{
|
{
|
||||||
var sceneEnum = (SceneType)index;
|
var sceneType = (SceneType)index;
|
||||||
_ = ChangeScene(sceneEnum);
|
_ = ChangeScene(sceneType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user