DDD-63 레스토랑 상태 기반 태스크 및 레스토랑 컨트롤러

This commit is contained in:
Jeonghyeon Ha 2025-07-17 15:20:30 +09:00
parent 929f7ecf55
commit 9bae1b0f41
10 changed files with 110 additions and 54 deletions

View File

@ -17,8 +17,8 @@ public enum GameFlowState
public class GameFlowManager : Singleton<GameFlowManager>, IManager public class GameFlowManager : Singleton<GameFlowManager>, IManager
{ {
public GameFlowDataSo GameFlowDataSo; public GameFlowDataSo GameFlowDataSo;
public GameFlowAssetsSo GameFlowAssetsSo;
public GameFlowSceneMappingSo GameFlowSceneMappingSo; public GameFlowSceneMappingSo GameFlowSceneMappingSo;
public List<IGameFlowHandler> FlowHandlers = new List<IGameFlowHandler>();
public void Init() public void Init()
{ {
@ -69,27 +69,6 @@ private async Task ReadyNewFlow(GameFlowState newFlowState)
{ {
GameFlowDataSo.CurrentGameState = newFlowState; GameFlowDataSo.CurrentGameState = newFlowState;
if (GameFlowAssetsSo.FlowItems.TryGetValue(newFlowState, out var stringKeys))
{
foreach (var key in stringKeys)
{
await AssetManager.LoadAsset<UnityEngine.Object>(key);
}
}
if (GameFlowAssetsSo.FlowAssets.TryGetValue(newFlowState, out var assetRefs))
{
foreach (var assetRef in assetRefs)
{
var obj = await AssetManager.LoadAsset<UnityEngine.Object>(assetRef);
if (obj is GameFlowReadyHandler handler)
{
await handler.OnReadyNewFlow(newFlowState);
}
}
}
OpenFlowScene(newFlowState); OpenFlowScene(newFlowState);
StartFlow(); StartFlow();

View File

@ -3,7 +3,7 @@
namespace DDD namespace DDD
{ {
public abstract class GameFlowReadyHandler : ScriptableObject public abstract class GameFlowTask : ScriptableObject
{ {
public abstract Task OnReadyNewFlow(GameFlowState newFlowState); public abstract Task OnReadyNewFlow(GameFlowState newFlowState);
} }

View File

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace DDD
{
public interface IGameFlowHandler
{
public Task OnReadyNewFlow(GameFlowState newFlowState);
}
}

View File

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

View File

@ -0,0 +1,76 @@
using System.Threading.Tasks;
using UnityEngine;
namespace DDD
{
public class RestaurantController : Singleton<RestaurantController>, IManager, IGameFlowHandler
{
private RestaurantEnvironmentState _restaurantEnvironmentState;
public RestaurantEnvironmentState RestaurantEnvironmentState => _restaurantEnvironmentState;
// TODO : GameManager에 등록되게 So에 추가해주세요.
public void Init()
{
LoadOrCreateRestaurantState();
RegisterFlowHandler();
}
public void PostInit()
{
GenerateDummyEnvironmentProps();// XXX : DUMMY! REMOVE THIS
}
private void RegisterFlowHandler()
{
GameFlowManager.Instance.FlowHandlers.Add(this);
}
private void LoadOrCreateRestaurantState()
{
// TODO : Load states from saved files. if none, create them.
_restaurantEnvironmentState = new RestaurantEnvironmentState();
}
private void GenerateDummyEnvironmentProps()
{
// Make dummy placement data
foreach (EnvironmentData prop in DataManager.Instance.EnvironmentDataSo.GetDataList())
{
if (prop.EnvironmentType != EnvironmentType.Prop)
{
continue;
}
for (int i = 0; i < 10; i++)
{
// Make random position
Vector2 randomPos = new Vector2(
Random.Range(-10f, 10f),
Random.Range(10f, 20f)
);
RestaurantEnvironmentData randomPropData = new RestaurantEnvironmentData();
randomPropData.Position = randomPos;
randomPropData.Id = prop.Id;
_restaurantEnvironmentState.RestaurantEnvironmentProps.Add(randomPropData);
}
}
}
public Task OnReadyNewFlow(GameFlowState newFlowState)
{
if (newFlowState == GameFlowState.ReadyForRestaurant)
{
CreateRestaurantPlayer createRestaurantPlayerJob = new CreateRestaurantPlayer();
CreateEnvironment createEnvironmentJob = new CreateEnvironment();
var playerHandle = createRestaurantPlayerJob.OnReadyNewFlow(newFlowState);
var propHandle = createEnvironmentJob.OnReadyNewFlow(newFlowState);
// Combine handles and return it
return Task.WhenAll(playerHandle, propHandle);
}
return Task.CompletedTask;
}
}
}

View File

@ -4,34 +4,18 @@
namespace DDD namespace DDD
{ {
[CreateAssetMenu(fileName = "CreateEnvironment", menuName = "GameFlow/CreateEnvironment")] [CreateAssetMenu(fileName = "CreateEnvironment", menuName = "GameFlow/CreateEnvironment")]
public class CreateEnvironment : GameFlowReadyHandler public class CreateEnvironment : GameFlowTask
{ {
public override async Task OnReadyNewFlow(GameFlowState newFlowState) public override async Task OnReadyNewFlow(GameFlowState newFlowState)
{ {
var baseRestaurantEnvironmentPrefab = await AssetManager.LoadAsset<GameObject>(CommonConstants.BaseRestaurantEnvironment); var baseRestaurantEnvironmentPrefab = await AssetManager.LoadAsset<GameObject>(CommonConstants.BaseRestaurantEnvironment);
for (int i = 0; i < 10; i++) var props = RestaurantController.Instance.RestaurantEnvironmentState.RestaurantEnvironmentProps;
foreach (var prop in props)
{ {
var restaurantEnvironment = Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>(); var restaurantEnvironment =
restaurantEnvironment.Initialize("Item_Environment_001"); Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
} restaurantEnvironment.Initialize(prop);
for (int i = 0; i < 10; i++)
{
var restaurantEnvironment = Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
restaurantEnvironment.Initialize("Item_Environment_002");
}
for (int i = 0; i < 10; i++)
{
var restaurantEnvironment = Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
restaurantEnvironment.Initialize("Item_Environment_003");
}
for (int i = 0; i < 10; i++)
{
var restaurantEnvironment = Instantiate(baseRestaurantEnvironmentPrefab).GetComponent<RestaurantEnvironment>();
restaurantEnvironment.Initialize("Item_Environment_004");
} }
} }
} }

View File

@ -12,11 +12,11 @@ public class RestaurantEnvironment : MonoBehaviour
private Transform _visualLook; private Transform _visualLook;
private Renderer _renderer; private Renderer _renderer;
public async void Initialize(string id) public async void Initialize(RestaurantEnvironmentData data)
{ {
await DataManager.Instance.WaitUntilInitialized(); await DataManager.Instance.WaitUntilInitialized();
EnvironmentData environmentData = DataManager.Instance.EnvironmentDataSo.GetDataById(id); EnvironmentData environmentData = DataManager.Instance.EnvironmentDataSo.GetDataById(data.Id);
_collider = GetComponent<Collider>(); _collider = GetComponent<Collider>();
_visualLook = transform.Find(CommonConstants.VisualLook); _visualLook = transform.Find(CommonConstants.VisualLook);
@ -48,12 +48,7 @@ public async void Initialize(string id)
_collider.isTrigger = environmentData.IsTrigger == 1; _collider.isTrigger = environmentData.IsTrigger == 1;
Vector2 randomPos = new Vector2( transform.position = new Vector3(data.Position.x, 0f, data.Position.y);
Random.Range(-10f, 10f),
Random.Range(10f, 20f)
);
transform.position = new Vector3(randomPos.x, 0f, randomPos.y);
transform.localScale = Vector3.one * environmentData.Size; transform.localScale = Vector3.one * environmentData.Size;
} }
} }

View File

@ -0,0 +1,13 @@
using System.Collections.Generic;
using UnityEngine;
namespace DDD
{
// [CreateAssetMenu(fileName = "FILENAME", menuName = "MENUNAME", order = 0)]
public class RestaurantEnvironmentState : ScriptableObject
{
// TODO : Public???
public List<RestaurantEnvironmentData> RestaurantEnvironmentProps = new List<RestaurantEnvironmentData>();
public List<RestaurantEnvironmentData> RestaurantEnvironmentObjects = new List<RestaurantEnvironmentData>();
}
}