101 lines
2.5 KiB
C#
101 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
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 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 void EndCurrentFlow()
|
|
{
|
|
|
|
}
|
|
|
|
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()
|
|
{
|
|
|
|
}
|
|
}
|
|
} |