2025-07-08 10:46:31 +00:00
|
|
|
using System;
|
2025-07-09 09:45:11 +00:00
|
|
|
using System.Collections;
|
2025-07-08 10:46:31 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2025-07-09 09:45:11 +00:00
|
|
|
using UnityEngine.AddressableAssets;
|
2025-07-08 10:46:31 +00:00
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
|
|
namespace DDD
|
|
|
|
{
|
|
|
|
|
|
|
|
public enum GameFlowState
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
ReadyForRestaurant = 1,
|
|
|
|
RunRestaurant = 2,
|
|
|
|
SettlementRestaurant = 3,
|
|
|
|
}
|
|
|
|
|
|
|
|
public class GameFlowData : ScriptableObject
|
|
|
|
{
|
|
|
|
public GameFlowState CurrentGameState;
|
|
|
|
}
|
2025-07-09 09:45:11 +00:00
|
|
|
|
|
|
|
[CreateAssetMenu(fileName = "GameFlowAssets", menuName = "GameFlow/GameFlowAssets")]
|
|
|
|
public class GameFlowAssets : ScriptableObject
|
|
|
|
{
|
|
|
|
public Dictionary<GameFlowState, List<string>> FlowItems = new();
|
|
|
|
public Dictionary<GameFlowState, List<AssetReference>> FlowAssets = new();
|
|
|
|
}
|
2025-07-08 10:46:31 +00:00
|
|
|
|
|
|
|
[CreateAssetMenu(fileName = "GameFlowSceneMapping", menuName = "GameFlow/GameFlowSceneMapping")]
|
|
|
|
public class GameFlowSceneMapping : ScriptableObject
|
|
|
|
{
|
2025-07-09 09:45:11 +00:00
|
|
|
public Dictionary<GameFlowState, Scene> FlowToSceneMapping = new();
|
2025-07-08 10:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class GameFlowManager : Singleton<GameFlowManager>, IManager
|
|
|
|
{
|
|
|
|
private GameFlowData _gameFlowData = null;
|
2025-07-09 09:45:11 +00:00
|
|
|
public GameFlowAssets GameFlowAssets = null;
|
2025-07-08 10:46:31 +00:00
|
|
|
public GameFlowSceneMapping GameFlowSceneMapping;
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
|
|
|
_gameFlowData = new GameFlowData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void PostInit()
|
|
|
|
{
|
2025-07-09 09:45:11 +00:00
|
|
|
SceneManager.Instance.OnSceneChanged += OnFlowSceneOpened;
|
2025-07-08 10:46:31 +00:00
|
|
|
|
|
|
|
if (IsGameStarted() == false)
|
|
|
|
{
|
2025-07-09 09:45:11 +00:00
|
|
|
ChangeFlow(GameFlowState.ReadyForRestaurant);
|
2025-07-08 10:46:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsGameStarted() => _gameFlowData.CurrentGameState != GameFlowState.None;
|
|
|
|
|
|
|
|
protected override void Awake()
|
|
|
|
{
|
|
|
|
base.Awake();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
}
|
2025-07-09 09:45:11 +00:00
|
|
|
|
|
|
|
private bool CanChangeFlow(GameFlowState newFlowState)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ChangeFlow(GameFlowState newFlowState)
|
|
|
|
{
|
|
|
|
StartCoroutine(ChangeFlowCoroutine(newFlowState));
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator ChangeFlowCoroutine(GameFlowState newFlowState)
|
|
|
|
{
|
|
|
|
if (CanChangeFlow(newFlowState) == false)
|
|
|
|
{
|
|
|
|
Debug.LogError("Can't change flow");
|
|
|
|
yield break;
|
|
|
|
}
|
|
|
|
|
|
|
|
EndCurrentFlow();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void EndCurrentFlow()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerator ReadyNewFlow(GameFlowState newFlowState)
|
|
|
|
{
|
|
|
|
OpenFlowScene(newFlowState);
|
|
|
|
|
|
|
|
// Ready Assets
|
|
|
|
if (GameFlowAssets.FlowItems.ContainsKey(newFlowState))
|
|
|
|
{
|
|
|
|
List<string> Items = GameFlowAssets.FlowItems[newFlowState];
|
|
|
|
// Addressables.LoadAssetsAsync(Items, null);
|
|
|
|
// TODO : 여러 에셋 로드하고, 콜백 받을때까지 기다리기
|
|
|
|
|
|
|
|
// Wait
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GameFlowAssets.FlowAssets.ContainsKey(newFlowState))
|
|
|
|
{
|
|
|
|
//List<AssetReference> Assets = GameFlowAssets.FlowItems[newFlowState];
|
|
|
|
// Addressables.LoadAssetsAsync(Assets, )
|
|
|
|
// TODO : 여러 에셋 로드하고, 콜백 받을때까지 기다리기
|
|
|
|
|
|
|
|
// Wait
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ready Scene
|
|
|
|
GetFlowScene(newFlowState, out var flowScene);
|
|
|
|
yield return new WaitUntil(() => _currentScene == flowScene );
|
|
|
|
|
|
|
|
StartFlow();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OpenFlowScene(GameFlowState newFlowState)
|
|
|
|
{
|
|
|
|
if (GetFlowScene(newFlowState, out var sceneToLoad))
|
|
|
|
{
|
|
|
|
SceneManager.Instance.RequestSceneLoad(sceneToLoad);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.Assert(false, "Scene not found!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Scene _currentScene;
|
|
|
|
public void OnFlowSceneOpened(Scene newScene)
|
|
|
|
{
|
|
|
|
_currentScene = newScene;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool GetFlowScene(GameFlowState flowState, out Scene scene)
|
|
|
|
{
|
|
|
|
if (GameFlowSceneMapping.FlowToSceneMapping.TryGetValue(flowState, out scene))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StartFlow()
|
|
|
|
{
|
|
|
|
// Broadcast new flow started
|
|
|
|
}
|
2025-07-08 10:46:31 +00:00
|
|
|
}
|
|
|
|
}
|