120 lines
3.3 KiB
C#
120 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.ResourceManagement.ResourceProviders;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace DDD
|
|
{
|
|
public enum GameFlowState
|
|
{
|
|
None = 0,
|
|
ReadyForRestaurant = 1,
|
|
RunRestaurant = 2,
|
|
SettlementRestaurant = 3,
|
|
}
|
|
|
|
public class GameFlowManager : Singleton<GameFlowManager>, IManager
|
|
{
|
|
public GameFlowDataSo GameFlowDataSo;
|
|
public GameFlowAssetsSo GameFlowAssetsSo;
|
|
public GameFlowSceneMappingSo GameFlowSceneMappingSo;
|
|
|
|
public void Init()
|
|
{
|
|
|
|
}
|
|
|
|
public async void PostInit()
|
|
{
|
|
try
|
|
{
|
|
if (IsGameStarted() == false)
|
|
{
|
|
await ChangeFlow(GameFlowState.ReadyForRestaurant);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogWarning(e);
|
|
}
|
|
}
|
|
|
|
public bool IsGameStarted() => GameFlowDataSo.CurrentGameState != GameFlowState.None;
|
|
|
|
public async Task ChangeFlow(GameFlowState newFlowState)
|
|
{
|
|
if (!CanChangeFlow(newFlowState))
|
|
{
|
|
Debug.LogError("Can't change flow");
|
|
return;
|
|
}
|
|
|
|
EndCurrentFlow();
|
|
|
|
await ReadyNewFlow(newFlowState);
|
|
}
|
|
|
|
private bool CanChangeFlow(GameFlowState newFlowState)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void EndCurrentFlow()
|
|
{
|
|
|
|
}
|
|
|
|
public async Task ReadyNewFlow(GameFlowState newFlowState)
|
|
{
|
|
if (GameFlowAssetsSo.FlowItems.TryGetValue(newFlowState, out var stringKeys))
|
|
{
|
|
List<Task<UnityEngine.Object>> loadTasks = new(stringKeys.Count);
|
|
foreach (var key in stringKeys)
|
|
{
|
|
loadTasks.Add(AssetManager.LoadAsset<UnityEngine.Object>(key));
|
|
}
|
|
|
|
await Task.WhenAll(loadTasks);
|
|
}
|
|
|
|
if (GameFlowAssetsSo.FlowAssets.TryGetValue(newFlowState, out var assetRefs))
|
|
{
|
|
List<Task<UnityEngine.Object>> loadTasks = new(assetRefs.Count);
|
|
foreach (var assetRef in assetRefs)
|
|
{
|
|
loadTasks.Add(AssetManager.LoadAsset<UnityEngine.Object>(assetRef));
|
|
}
|
|
|
|
await Task.WhenAll(loadTasks);
|
|
}
|
|
|
|
OpenFlowScene(newFlowState);
|
|
|
|
StartFlow();
|
|
}
|
|
|
|
public void OpenFlowScene(GameFlowState newFlowState)
|
|
{
|
|
if (GetFlowScene(newFlowState, out var sceneToLoad))
|
|
{
|
|
SceneManager.Instance.ActivateScene(sceneToLoad);
|
|
}
|
|
else
|
|
{
|
|
Debug.Assert(false, "Scene not found!");
|
|
}
|
|
}
|
|
|
|
public bool GetFlowScene(GameFlowState flowState, out SceneType sceneType)
|
|
{
|
|
return GameFlowSceneMappingSo.FlowToSceneMapping.TryGetValue(flowState, out sceneType);
|
|
}
|
|
|
|
public void StartFlow()
|
|
{
|
|
// Broadcast new flow started
|
|
}
|
|
}
|
|
} |