ProjectDDD/Assets/_DDD/_Scripts/GameFlow/GameFlowManager.cs
2025-07-21 12:09:15 +09:00

106 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace DDD
{
public enum GameFlowState
{
None = 0,
ReadyForRestaurant = 1,
RunRestaurant = 2,
SettlementRestaurant = 3,
}
public class GameFlowManager : Singleton<GameFlowManager>, IManager
{
public GameFlowDataSo GameFlowDataSo;
public GameFlowSceneMappingSo GameFlowSceneMappingSo;
public List<IGameFlowHandler> FlowHandlers = new List<IGameFlowHandler>();
public void Init()
{
GameFlowDataSo.CurrentGameState = GameFlowState.None;
}
public void PostInit()
{
try
{
if (IsGameStarted() == false)
{
ChangeFlow(GameFlowState.ReadyForRestaurant);
}
}
catch (Exception e)
{
Debug.LogWarning(e);
}
}
private bool IsGameStarted() => GameFlowDataSo.CurrentGameState != GameFlowState.None;
public void ChangeFlow(GameFlowState newFlowState)
{
if (!CanChangeFlow(newFlowState))
{
Debug.LogError("Can't change flow");
return;
}
EndCurrentFlow();
ReadyNewFlow(newFlowState);
}
private bool CanChangeFlow(GameFlowState newFlowState)
{
return true;
}
private void EndCurrentFlow()
{
}
private void ReadyNewFlow(GameFlowState newFlowState)
{
GameFlowDataSo.CurrentGameState = newFlowState;
OpenFlowScene(newFlowState);
StartFlow();
}
private async void OpenFlowScene(GameFlowState newFlowState)
{
try
{
if (GetFlowScene(newFlowState, out var sceneToLoad))
{
await SceneManager.Instance.ActivateScene(sceneToLoad);
}
else
{
Debug.Assert(false, "Scene not found!");
}
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
}
private bool GetFlowScene(GameFlowState flowState, out SceneType sceneType)
{
return GameFlowSceneMappingSo.FlowToSceneMapping.TryGetValue(flowState, out sceneType);
}
private void StartFlow()
{
}
}
}