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;
|
2025-07-10 05:48:44 +00:00
|
|
|
using Sirenix.OdinInspector;
|
2025-07-08 10:46:31 +00:00
|
|
|
using UnityEngine;
|
2025-07-09 09:45:11 +00:00
|
|
|
using UnityEngine.AddressableAssets;
|
2025-07-08 10:46:31 +00:00
|
|
|
using UnityEngine.SceneManagement;
|
2025-07-10 05:48:44 +00:00
|
|
|
using UnityEngine.Serialization;
|
2025-07-08 10:46:31 +00:00
|
|
|
|
|
|
|
namespace DDD
|
|
|
|
{
|
|
|
|
|
|
|
|
public enum GameFlowState
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
ReadyForRestaurant = 1,
|
|
|
|
RunRestaurant = 2,
|
|
|
|
SettlementRestaurant = 3,
|
|
|
|
}
|
|
|
|
|
2025-07-10 05:48:44 +00:00
|
|
|
public class GameFlowDataSo : ScriptableObject
|
2025-07-08 10:46:31 +00:00
|
|
|
{
|
|
|
|
public GameFlowState CurrentGameState;
|
|
|
|
}
|
2025-07-09 09:45:11 +00:00
|
|
|
|
2025-07-10 05:48:44 +00:00
|
|
|
[CreateAssetMenu(fileName = "GameFlowAssetsSo", menuName = "GameFlow/GameFlowAssetsSo")]
|
|
|
|
public class GameFlowAssetsSo : ScriptableObject
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
2025-07-10 05:48:44 +00:00
|
|
|
[ShowInInspector]
|
2025-07-09 09:45:11 +00:00
|
|
|
public Dictionary<GameFlowState, List<string>> FlowItems = new();
|
2025-07-10 05:48:44 +00:00
|
|
|
|
|
|
|
[ShowInInspector]
|
2025-07-09 09:45:11 +00:00
|
|
|
public Dictionary<GameFlowState, List<AssetReference>> FlowAssets = new();
|
|
|
|
}
|
2025-07-08 10:46:31 +00:00
|
|
|
|
2025-07-10 05:48:44 +00:00
|
|
|
[CreateAssetMenu(fileName = "GameFlowSceneMappingSo", menuName = "GameFlow/GameFlowSceneMappingSo")]
|
|
|
|
public class GameFlowSceneMappingSo : ScriptableObject
|
2025-07-08 10:46:31 +00:00
|
|
|
{
|
2025-07-10 05:48:44 +00:00
|
|
|
[ShowInInspector]
|
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
|
|
|
|
{
|
2025-07-10 05:48:44 +00:00
|
|
|
private GameFlowDataSo _gameFlowDataSo;
|
|
|
|
public GameFlowAssetsSo GameFlowAssetsSo;
|
|
|
|
public GameFlowSceneMappingSo GameFlowSceneMappingSo;
|
2025-07-08 10:46:31 +00:00
|
|
|
|
|
|
|
public void Init()
|
|
|
|
{
|
2025-07-10 05:48:44 +00:00
|
|
|
_gameFlowDataSo = ScriptableObject.CreateInstance<GameFlowDataSo>();
|
2025-07-08 10:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-07-10 05:48:44 +00:00
|
|
|
public bool IsGameStarted() => _gameFlowDataSo.CurrentGameState != GameFlowState.None;
|
2025-07-08 10:46:31 +00:00
|
|
|
|
|
|
|
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
|
2025-07-10 05:48:44 +00:00
|
|
|
if (GameFlowAssetsSo.FlowItems.ContainsKey(newFlowState))
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
2025-07-10 05:48:44 +00:00
|
|
|
List<string> Items = GameFlowAssetsSo.FlowItems[newFlowState];
|
2025-07-09 09:45:11 +00:00
|
|
|
// Addressables.LoadAssetsAsync(Items, null);
|
|
|
|
// TODO : 여러 에셋 로드하고, 콜백 받을때까지 기다리기
|
|
|
|
|
|
|
|
// Wait
|
|
|
|
}
|
|
|
|
|
2025-07-10 05:48:44 +00:00
|
|
|
if (GameFlowAssetsSo.FlowAssets.ContainsKey(newFlowState))
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
|
|
|
//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)
|
|
|
|
{
|
2025-07-10 05:48:44 +00:00
|
|
|
if (GameFlowSceneMappingSo.FlowToSceneMapping.TryGetValue(flowState, out scene))
|
2025-07-09 09:45:11 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StartFlow()
|
|
|
|
{
|
|
|
|
// Broadcast new flow started
|
|
|
|
}
|
2025-07-08 10:46:31 +00:00
|
|
|
}
|
|
|
|
}
|