using System; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; namespace DDD { [Flags] public enum GameFlowState : uint { None = 0u, ReadyForRestaurant = 1u, RunRestaurant = 1u << 1, SettlementRestaurant = 1u << 2, All = 0xFFFFFFFFu } public class GameFlowManager : Singleton, IManager { public GameFlowDataSo GameFlowDataSo; public GameFlowSceneMappingSo GameFlowSceneMappingSo; public List FlowHandlers = new List(); public void PreInit() { GameFlowDataSo.CurrentGameState = GameFlowState.None; } public Task Init() { return Task.CompletedTask;; } public void PostInit() { if (IsGameStarted() == false) { ChangeFlow(GameFlowState.ReadyForRestaurant); } } 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 async Task EndCurrentFlow() { var endCurrentFlowState = GameFlowDataSo.CurrentGameState; foreach (var handler in FlowHandlers) { await handler.OnExitCurrentFlow(endCurrentFlowState); } } private async Task ReadyNewFlow(GameFlowState newFlowState) { GameFlowDataSo.CurrentGameState = newFlowState; foreach (var handler in FlowHandlers) { await handler.OnReadyNewFlow(newFlowState); } await OpenFlowScene(newFlowState); StartFlow(); } private async Task OpenFlowScene(GameFlowState newFlowState) { if (GetFlowScene(newFlowState)) { await SceneManager.Instance.ActivateScene(newFlowState); } else { Debug.Assert(false, "Scene not found!"); } } private bool GetFlowScene(GameFlowState flowState) { return GameFlowSceneMappingSo.FlowToSceneMapping.ContainsKey(flowState); } private void StartFlow() { } } }