2025-07-08 10:46:31 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2025-07-10 10:18:07 +00:00
|
|
|
using System.Threading.Tasks;
|
2025-07-08 10:46:31 +00:00
|
|
|
using UnityEngine;
|
2025-07-11 05:48:49 +00:00
|
|
|
using UnityEngine.AddressableAssets;
|
2025-07-08 10:46:31 +00:00
|
|
|
|
|
|
|
namespace DDD
|
|
|
|
{
|
|
|
|
public enum GameFlowState
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
ReadyForRestaurant = 1,
|
|
|
|
RunRestaurant = 2,
|
|
|
|
SettlementRestaurant = 3,
|
2025-07-10 10:18:07 +00:00
|
|
|
}
|
2025-07-08 10:46:31 +00:00
|
|
|
|
|
|
|
public class GameFlowManager : Singleton<GameFlowManager>, IManager
|
|
|
|
{
|
2025-07-10 10:18:07 +00:00
|
|
|
public GameFlowDataSo GameFlowDataSo;
|
2025-07-10 05:48:44 +00:00
|
|
|
public GameFlowSceneMappingSo GameFlowSceneMappingSo;
|
2025-07-17 06:20:30 +00:00
|
|
|
public List<IGameFlowHandler> FlowHandlers = new List<IGameFlowHandler>();
|
2025-07-08 10:46:31 +00:00
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
2025-07-11 05:48:49 +00:00
|
|
|
GameFlowDataSo.CurrentGameState = GameFlowState.None;
|
2025-07-08 10:46:31 +00:00
|
|
|
}
|
|
|
|
|
2025-07-21 03:09:15 +00:00
|
|
|
public void PostInit()
|
2025-07-08 10:46:31 +00:00
|
|
|
{
|
2025-07-10 10:18:07 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (IsGameStarted() == false)
|
|
|
|
{
|
2025-07-21 03:09:15 +00:00
|
|
|
ChangeFlow(GameFlowState.ReadyForRestaurant);
|
2025-07-10 10:18:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
2025-07-08 10:46:31 +00:00
|
|
|
{
|
2025-07-10 10:18:07 +00:00
|
|
|
Debug.LogWarning(e);
|
2025-07-08 10:46:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-07-11 05:48:49 +00:00
|
|
|
private bool IsGameStarted() => GameFlowDataSo.CurrentGameState != GameFlowState.None;
|
2025-07-08 10:46:31 +00:00
|
|
|
|
2025-07-21 03:09:15 +00:00
|
|
|
public void ChangeFlow(GameFlowState newFlowState)
|
2025-07-08 10:46:31 +00:00
|
|
|
{
|
2025-07-10 10:18:07 +00:00
|
|
|
if (!CanChangeFlow(newFlowState))
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
|
|
|
Debug.LogError("Can't change flow");
|
2025-07-10 10:18:07 +00:00
|
|
|
return;
|
2025-07-09 09:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EndCurrentFlow();
|
|
|
|
|
2025-07-21 03:09:15 +00:00
|
|
|
ReadyNewFlow(newFlowState);
|
2025-07-10 10:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private bool CanChangeFlow(GameFlowState newFlowState)
|
|
|
|
{
|
|
|
|
return true;
|
2025-07-09 09:45:11 +00:00
|
|
|
}
|
|
|
|
|
2025-07-11 05:48:49 +00:00
|
|
|
private void EndCurrentFlow()
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-07-21 03:09:15 +00:00
|
|
|
private void ReadyNewFlow(GameFlowState newFlowState)
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
2025-07-11 05:48:49 +00:00
|
|
|
GameFlowDataSo.CurrentGameState = newFlowState;
|
|
|
|
|
2025-07-10 10:18:07 +00:00
|
|
|
OpenFlowScene(newFlowState);
|
2025-07-09 09:45:11 +00:00
|
|
|
|
|
|
|
StartFlow();
|
|
|
|
}
|
|
|
|
|
2025-07-11 05:48:49 +00:00
|
|
|
private async void OpenFlowScene(GameFlowState newFlowState)
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
2025-07-11 05:48:49 +00:00
|
|
|
try
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
2025-07-11 05:48:49 +00:00
|
|
|
if (GetFlowScene(newFlowState, out var sceneToLoad))
|
|
|
|
{
|
2025-07-14 05:57:10 +00:00
|
|
|
await SceneManager.Instance.ActivateScene(sceneToLoad);
|
2025-07-11 05:48:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.Assert(false, "Scene not found!");
|
|
|
|
}
|
2025-07-09 09:45:11 +00:00
|
|
|
}
|
2025-07-11 05:48:49 +00:00
|
|
|
catch (Exception e)
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
2025-07-11 05:48:49 +00:00
|
|
|
Debug.LogError(e.Message);
|
2025-07-09 09:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-07-11 05:48:49 +00:00
|
|
|
private bool GetFlowScene(GameFlowState flowState, out SceneType sceneType)
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
2025-07-10 10:18:07 +00:00
|
|
|
return GameFlowSceneMappingSo.FlowToSceneMapping.TryGetValue(flowState, out sceneType);
|
2025-07-09 09:45:11 +00:00
|
|
|
}
|
|
|
|
|
2025-07-11 05:48:49 +00:00
|
|
|
private void StartFlow()
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
2025-07-11 05:48:49 +00:00
|
|
|
|
2025-07-09 09:45:11 +00:00
|
|
|
}
|
2025-07-08 10:46:31 +00:00
|
|
|
}
|
|
|
|
}
|