게임 플로우 변경 (PreInit 추가)

This commit is contained in:
NTG_Lenovo 2025-07-21 13:11:38 +09:00
parent ffd534cb13
commit f0e24f4c43
18 changed files with 116 additions and 88 deletions

View File

@ -16,7 +16,7 @@ MonoBehaviour:
m_GUID: 30e7f67fe9aaa7849a34c9b6e2bc53ae m_GUID: 30e7f67fe9aaa7849a34c9b6e2bc53ae
m_SerializeEntries: m_SerializeEntries:
- m_GUID: 0912c3de85fd61848a41575faa2794ed - m_GUID: 0912c3de85fd61848a41575faa2794ed
m_Address: CreateEnvironment m_Address: CreateEnvironmentSo
m_ReadOnly: 0 m_ReadOnly: 0
m_SerializedLabels: [] m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0 FlaggedDuringContentUpdateRestriction: 0
@ -56,7 +56,7 @@ MonoBehaviour:
- Atlas - Atlas
FlaggedDuringContentUpdateRestriction: 0 FlaggedDuringContentUpdateRestriction: 0
- m_GUID: 47e757b9a170ab649af14c4d7b80ac41 - m_GUID: 47e757b9a170ab649af14c4d7b80ac41
m_Address: CreateRestaurantPlayer m_Address: CreateRestaurantPlayerSo
m_ReadOnly: 0 m_ReadOnly: 0
m_SerializedLabels: [] m_SerializedLabels: []
FlaggedDuringContentUpdateRestriction: 0 FlaggedDuringContentUpdateRestriction: 0

View File

@ -10,5 +10,5 @@ MonoBehaviour:
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 419e829d5eec9544e94be59817cdb69c, type: 3} m_Script: {fileID: 11500000, guid: 419e829d5eec9544e94be59817cdb69c, type: 3}
m_Name: CreateEnvironment m_Name: CreateEnvironmentSo
m_EditorClassIdentifier: m_EditorClassIdentifier:

View File

@ -10,6 +10,6 @@ MonoBehaviour:
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 246a7785bd15ac84b9f240005b987f1f, type: 3} m_Script: {fileID: 11500000, guid: 246a7785bd15ac84b9f240005b987f1f, type: 3}
m_Name: CreateRestaurantPlayer m_Name: CreateRestaurantPlayerSo
m_EditorClassIdentifier: m_EditorClassIdentifier:
_spawnPosition: {x: 0, y: 0, z: 15} _spawnPosition: {x: 0, y: 0, z: 15}

View File

@ -15,21 +15,19 @@ namespace DDD
{ {
public class AssetManager : Singleton<AssetManager>, IManager public class AssetManager : Singleton<AssetManager>, IManager
{ {
public void Init() public void PreInit()
{ {
} }
public async void PostInit() public async Task Init()
{
try
{ {
await Addressables.InitializeAsync().Task; await Addressables.InitializeAsync().Task;
} }
catch (Exception e)
public void PostInit()
{ {
Debug.Assert(false, $"Addressables initialization failed\n{e}");
}
} }
public static async Task<T> LoadAsset<T>(string key) where T : UnityEngine.Object public static async Task<T> LoadAsset<T>(string key) where T : UnityEngine.Object

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
using Unity.Cinemachine; using Unity.Cinemachine;
@ -17,11 +18,16 @@ public class CameraManager : Singleton<CameraManager>, IManager
private CinemachineBrain _cinemachineBrain; private CinemachineBrain _cinemachineBrain;
public void Init() public void PreInit()
{ {
_cinemachineBrain = GetComponent<CinemachineBrain>(); _cinemachineBrain = GetComponent<CinemachineBrain>();
} }
public Task Init()
{
return Task.CompletedTask;;
}
public void PostInit() public void PostInit()
{ {

View File

@ -16,14 +16,12 @@ public class DataManager : Singleton<DataManager>, IManager
public bool IsInitialized { get; private set; } public bool IsInitialized { get; private set; }
public void Init() public void PreInit()
{ {
} }
public async void PostInit() public async Task Init()
{
try
{ {
ItemDataSo = await AssetManager.LoadAsset<ItemDataSo>(DataConstants.ItemDataSo); ItemDataSo = await AssetManager.LoadAsset<ItemDataSo>(DataConstants.ItemDataSo);
FoodDataSo = await AssetManager.LoadAsset<FoodDataSo>(DataConstants.FoodDataSo); FoodDataSo = await AssetManager.LoadAsset<FoodDataSo>(DataConstants.FoodDataSo);
@ -53,10 +51,10 @@ public async void PostInit()
IsInitialized = true; IsInitialized = true;
} }
catch (Exception e)
public void PostInit()
{ {
Debug.LogError($"So bind failed\n{e.Message}");
}
} }
public async Task WaitUntilInitialized() public async Task WaitUntilInitialized()

View File

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets;
namespace DDD namespace DDD
{ {
@ -20,25 +19,23 @@ public class GameFlowManager : Singleton<GameFlowManager>, IManager
public GameFlowSceneMappingSo GameFlowSceneMappingSo; public GameFlowSceneMappingSo GameFlowSceneMappingSo;
public List<IGameFlowHandler> FlowHandlers = new List<IGameFlowHandler>(); public List<IGameFlowHandler> FlowHandlers = new List<IGameFlowHandler>();
public void Init() public void PreInit()
{ {
GameFlowDataSo.CurrentGameState = GameFlowState.None; GameFlowDataSo.CurrentGameState = GameFlowState.None;
} }
public void PostInit() public Task Init()
{ {
try return Task.CompletedTask;;
}
public void PostInit()
{ {
if (IsGameStarted() == false) if (IsGameStarted() == false)
{ {
ChangeFlow(GameFlowState.ReadyForRestaurant); ChangeFlow(GameFlowState.ReadyForRestaurant);
} }
} }
catch (Exception e)
{
Debug.LogWarning(e);
}
}
private bool IsGameStarted() => GameFlowDataSo.CurrentGameState != GameFlowState.None; private bool IsGameStarted() => GameFlowDataSo.CurrentGameState != GameFlowState.None;
@ -65,10 +62,15 @@ private void EndCurrentFlow()
} }
private void ReadyNewFlow(GameFlowState newFlowState) private async void ReadyNewFlow(GameFlowState newFlowState)
{ {
GameFlowDataSo.CurrentGameState = newFlowState; GameFlowDataSo.CurrentGameState = newFlowState;
foreach (var handler in FlowHandlers)
{
await handler.OnReadyNewFlow(newFlowState);
}
OpenFlowScene(newFlowState); OpenFlowScene(newFlowState);
StartFlow(); StartFlow();

View File

@ -14,11 +14,16 @@ public class FadeManager : Singleton<FadeManager>, IManager
private CanvasGroup _canvasGroup; private CanvasGroup _canvasGroup;
public void Init() public void PreInit()
{ {
_canvasGroup = GetComponent<CanvasGroup>(); _canvasGroup = GetComponent<CanvasGroup>();
} }
public Task Init()
{
return Task.CompletedTask;;
}
public void PostInit() public void PostInit()
{ {
_canvasGroup.alpha = 0f; _canvasGroup.alpha = 0f;

View File

@ -10,7 +10,7 @@ public class GameManager : Singleton<GameManager>
private List<Singleton> _managerInstances; private List<Singleton> _managerInstances;
protected void Start() protected async void Start()
{ {
base.OnAwake(); base.OnAwake();
@ -33,7 +33,15 @@ protected void Start()
_managerInstances.Add(managerInstance); _managerInstances.Add(managerInstance);
if (managerInstance is IManager manager) if (managerInstance is IManager manager)
{ {
manager.Init(); manager.PreInit();
}
}
foreach (var managerInstance in _managerInstances)
{
if (managerInstance is IManager manager)
{
await manager.Init();
} }
} }
foreach (var managerInstance in _managerInstances) foreach (var managerInstance in _managerInstances)

View File

@ -1,8 +1,11 @@
using System.Threading.Tasks;
namespace DDD namespace DDD
{ {
public interface IManager public interface IManager
{ {
void Init(); void PreInit();
Task Init();
void PostInit(); void PostInit();
} }
} }

View File

@ -24,13 +24,13 @@ public class SceneManager : Singleton<SceneManager>, IManager
private SceneInstance _currentSceneInstance; private SceneInstance _currentSceneInstance;
public Action<SceneInstance> OnSceneChanged; public Action<SceneInstance> OnSceneChanged;
public void Init() public void PreInit()
{ {
Array sceneTypeArray = Enum.GetValues(typeof(SceneType)); Array sceneTypeArray = Enum.GetValues(typeof(SceneType));
_loadedScenes = new Dictionary<SceneType, SceneInstance>(sceneTypeArray.Length); _loadedScenes = new Dictionary<SceneType, SceneInstance>(sceneTypeArray.Length);
} }
public async void PostInit() public async Task Init()
{ {
try try
{ {
@ -47,6 +47,11 @@ public async void PostInit()
} }
} }
public void PostInit()
{
}
public SceneInstance GetSceneInstance(SceneType sceneType) => _loadedScenes[sceneType]; public SceneInstance GetSceneInstance(SceneType sceneType) => _loadedScenes[sceneType];
public async Task PreloadSceneAsync(SceneType sceneType) public async Task PreloadSceneAsync(SceneType sceneType)

View File

@ -3,8 +3,8 @@
namespace DDD namespace DDD
{ {
[CreateAssetMenu(fileName = "CreateRestaurantPlayer", menuName = "GameFlow/CreateRestaurantPlayer")] [CreateAssetMenu(fileName = "CreateRestaurantPlayerSo", menuName = "GameFlow/CreateRestaurantPlayerSo")]
public class CreateRestaurantPlayer : GameFlowTask public class CreateRestaurantPlayerSo : GameFlowTask
{ {
[SerializeField] [SerializeField]
private Vector3 _spawnPosition; private Vector3 _spawnPosition;

View File

@ -8,14 +8,20 @@ public class RestaurantController : Singleton<RestaurantController>, IManager, I
private RestaurantEnvironmentState _restaurantEnvironmentState; private RestaurantEnvironmentState _restaurantEnvironmentState;
public RestaurantEnvironmentState RestaurantEnvironmentState => _restaurantEnvironmentState; public RestaurantEnvironmentState RestaurantEnvironmentState => _restaurantEnvironmentState;
// TODO : GameManager에 등록되게 So에 추가해주세요. private const string CreateRestaurantPlayerSo = "CreateRestaurantPlayerSo";
private const string CreateEnvironmentSo = "CreateEnvironmentSo";
public void Init() public void PreInit()
{ {
LoadOrCreateRestaurantState(); LoadOrCreateRestaurantState();
RegisterFlowHandler(); RegisterFlowHandler();
} }
public Task Init()
{
return Task.CompletedTask;;
}
public void PostInit() public void PostInit()
{ {
GenerateDummyEnvironmentProps();// XXX : DUMMY! REMOVE THIS GenerateDummyEnvironmentProps();// XXX : DUMMY! REMOVE THIS
@ -29,7 +35,7 @@ private void RegisterFlowHandler()
private void LoadOrCreateRestaurantState() private void LoadOrCreateRestaurantState()
{ {
// TODO : Load states from saved files. if none, create them. // TODO : Load states from saved files. if none, create them.
_restaurantEnvironmentState = new RestaurantEnvironmentState(); _restaurantEnvironmentState = ScriptableObject.CreateInstance<RestaurantEnvironmentState>();
} }
private void GenerateDummyEnvironmentProps() private void GenerateDummyEnvironmentProps()
@ -58,19 +64,17 @@ private void GenerateDummyEnvironmentProps()
} }
public Task OnReadyNewFlow(GameFlowState newFlowState) public async Task OnReadyNewFlow(GameFlowState newFlowState)
{ {
if (newFlowState == GameFlowState.ReadyForRestaurant) if (newFlowState == GameFlowState.ReadyForRestaurant)
{ {
CreateRestaurantPlayer createRestaurantPlayerJob = new CreateRestaurantPlayer(); CreateRestaurantPlayerSo createRestaurantPlayerSoJob = await AssetManager.LoadAsset<CreateRestaurantPlayerSo>(CreateRestaurantPlayerSo);
CreateEnvironment createEnvironmentJob = new CreateEnvironment(); CreateEnvironmentSo createEnvironmentSoJob = await AssetManager.LoadAsset<CreateEnvironmentSo>(CreateEnvironmentSo);
var playerHandle = createRestaurantPlayerJob.OnReadyNewFlow(newFlowState); var playerHandle = createRestaurantPlayerSoJob.OnReadyNewFlow(newFlowState);
var propHandle = createEnvironmentJob.OnReadyNewFlow(newFlowState); var propHandle = createEnvironmentSoJob.OnReadyNewFlow(newFlowState);
// Combine handles and return it // Combine handles and return it
return Task.WhenAll(playerHandle, propHandle); await Task.WhenAll(playerHandle, propHandle);
} }
return Task.CompletedTask;
} }
} }
} }

View File

@ -3,8 +3,8 @@
namespace DDD namespace DDD
{ {
[CreateAssetMenu(fileName = "CreateEnvironment", menuName = "GameFlow/CreateEnvironment")] [CreateAssetMenu(fileName = "CreateEnvironmentSo", menuName = "GameFlow/CreateEnvironmentSo")]
public class CreateEnvironment : GameFlowTask public class CreateEnvironmentSo : GameFlowTask
{ {
public override async Task OnReadyNewFlow(GameFlowState newFlowState) public override async Task OnReadyNewFlow(GameFlowState newFlowState)
{ {
@ -13,8 +13,7 @@ public override async Task OnReadyNewFlow(GameFlowState newFlowState)
var props = RestaurantController.Instance.RestaurantEnvironmentState.RestaurantEnvironmentProps; var props = RestaurantController.Instance.RestaurantEnvironmentState.RestaurantEnvironmentProps;
foreach (var prop in props) foreach (var prop in props)
{ {
var restaurantEnvironment = var restaurantEnvironment = Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
restaurantEnvironment.Initialize(prop); restaurantEnvironment.Initialize(prop);
} }
} }