결산 작업 중

This commit is contained in:
NTG 2025-09-02 21:34:18 +09:00
parent 33d72c3ba5
commit 15856c51fe
9 changed files with 123 additions and 21 deletions

View File

@ -3723,10 +3723,6 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5495376218471957137, guid: 1b0cdbed9c1b7d148b63ac3b70f9a28a, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5980190398288299945, guid: 1b0cdbed9c1b7d148b63ac3b70f9a28a, type: 3}
propertyPath: m_AnchorMax.x
value: 1
@ -3833,7 +3829,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 8146336867650838388, guid: 1b0cdbed9c1b7d148b63ac3b70f9a28a, type: 3}
propertyPath: m_AnchoredPosition.y
value: -15
value: -96.38
objectReference: {fileID: 0}
- target: {fileID: 8292253660733231715, guid: 1b0cdbed9c1b7d148b63ac3b70f9a28a, type: 3}
propertyPath: m_AnchorMax.y

Binary file not shown.

View File

@ -1,7 +1,4 @@
using System.Threading.Tasks;
using Opsive.BehaviorDesigner.Runtime;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace DDD.Restaurant
{
@ -16,6 +13,14 @@ protected override void Awake()
base.Awake();
_customerAi = GetComponent<ICustomerAi>();
}
private void OnDestroy()
{
if (RestaurantState.Instance?.RunState != null)
{
RestaurantState.Instance.RunState.RemoveCustomer(gameObject);
}
}
public void Initialize(CustomerDataEntry customerDataEntry)
{

View File

@ -43,6 +43,8 @@ public async Task<GameObject> CreateAsync(CustomerSpawnArgs args)
{
initializer.Initialize(args.CustomerDataEntry);
}
RestaurantState.Instance.RunState.AddCustomer(newCustomer);
return newCustomer;
}

View File

@ -116,8 +116,12 @@ SpawnSchedule MakeSchedule() => scheduleBuilder.Build(new SpawnScheduleBuildArgs
{
break;
}
if (_spawnSchedule.TryDequeue(out var customerId) == false) break;
if (_spawnSchedule.TryDequeue(out var customerId) == false)
{
_restaurantRunStateSo.SetSpawnCompleted(true);
break;
}
if (_customerDataAsset.TryGetDataById(customerId, out var customerData))
{
@ -134,6 +138,14 @@ await _iCustomerFactory.CreateAsync(new CustomerSpawnArgs
await Awaitable.WaitForSecondsAsync(wait, token);
}
if (_restaurantRunStateSo.GetSpawnCompleted() && token.IsCancellationRequested == false)
{
await WaitForAllCustomersToLeave(token);
// 모든 손님이 떠났으면 다음 flow로 전환
await TransitionToNextFlow();
}
}
private static ISpawnScheduleBuilder CreateBuilder(SpawnType type)
@ -145,5 +157,28 @@ private static ISpawnScheduleBuilder CreateBuilder(SpawnType type)
_ => new RandomSpawnScheduleBuilder()
};
}
private async Task WaitForAllCustomersToLeave(CancellationToken token)
{
const float checkInterval = 1f; // 1초마다 체크
while (!token.IsCancellationRequested && Application.isPlaying)
{
if (_restaurantRunStateSo.AllCustomersGone())
{
Debug.Log("[RunController] 모든 손님이 떠났습니다.");
break;
}
await Awaitable.WaitForSecondsAsync(checkInterval, token);
}
}
private async Task TransitionToNextFlow()
{
_restaurantRunStateSo.ClearCustomers();
await GameFlowManager.Instance.ChangeFlow(GameFlowState.SettlementRestaurant);
}
}
}

View File

@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEngine;
namespace DDD
@ -6,10 +7,46 @@ public class RestaurantRunState : ScriptableObject
{
private Vector3 _spawnPoint = new(5f, 0f, 4f);
public Vector3 SpawnPoint => _spawnPoint;
private List<GameObject> _activeCustomers = new();
private bool _spawnCompleted;
public void InitializeSpawnPoint(Vector3 spawnPoint)
{
_spawnPoint = spawnPoint;
}
public void AddCustomer(GameObject customer)
{
if (_activeCustomers.Contains(customer) == false)
{
_activeCustomers.Add(customer);
}
}
public void RemoveCustomer(GameObject customer)
{
_activeCustomers.Remove(customer);
}
public void SetSpawnCompleted(bool completed)
{
_spawnCompleted = completed;
}
public bool AllCustomersGone()
{
// null 체크 후 실제로 활성화된 손님이 없는지 확인
_activeCustomers.RemoveAll(customer => customer == null);
return _activeCustomers.Count == 0;
}
public void ClearCustomers()
{
_activeCustomers.Clear();
_spawnCompleted = false;
}
public bool GetSpawnCompleted() => _spawnCompleted;
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
namespace DDD.Restaurant
@ -31,12 +32,26 @@ public void CustomerSettlement(CustomerType customerType, int price, string cook
TotalRevenue += price;
SoldCookingCounts.TryAdd(cookingId, 1);
if (SoldCookingCounts.TryAdd(cookingId, 1) == false)
{
SoldCookingCounts[cookingId]++;
}
}
public void SaveSettlementResult()
{
// TODO : 골드 경험치 등 필요 데이터 저장
}
public void CompleteSettlement()
{
GameState.Instance.LevelState.IncreaseLevel();
//_ = ChangeFlow();
}
// private async Task ChangeFlow()
// {
//
// }
}
}

View File

@ -21,6 +21,9 @@ protected override GameObject GetInitialSelected()
protected override void OnCreatedInitializePopup()
{
_viewModel.OnCompletedSettlement += HandleCompleteSettlement;
_confirmButton.AddListener(HandleCompleteSettlement);
BindingHelper.BindText(_bindingContext, _totalRevenueLabel, nameof(_viewModel.TotalRevenue));
BindingHelper.BindText(_bindingContext, _normalCustomersLabel, nameof(_viewModel.NormalCustomers));
BindingHelper.BindText(_bindingContext, _specialCustomersLabel, nameof(_viewModel.SpecialCustomers));
@ -62,5 +65,11 @@ private void HandleInteract1()
var interactable = selected?.GetComponent<IInteractableUi>();
interactable?.OnInteract();
}
private void HandleCompleteSettlement()
{
Close();
_viewModel.SettlementState.CompleteSettlement();
}
}
}

View File

@ -1,3 +1,4 @@
using System;
using TMPro;
using UnityEngine;
@ -5,8 +6,8 @@ namespace DDD.Restaurant
{
public class SettlementViewModel : SimpleViewModel
{
private RestaurantSettlementData _settlementData;
private RestaurantSettlementState _settlementState;
public RestaurantSettlementData SettlementData;
public RestaurantSettlementState SettlementState;
private string _totalRevenue;
public string TotalRevenue
@ -29,10 +30,12 @@ public string SpecialCustomers
private set => SetField(ref _specialCustomers, value);
}
public Action OnCompletedSettlement;
public override void Initialize()
{
_settlementData = RestaurantData.Instance.SettlementData;
_settlementState = RestaurantState.Instance.SettlementState;
SettlementData = RestaurantData.Instance.SettlementData;
SettlementState = RestaurantState.Instance.SettlementState;
}
public override void Cleanup()
@ -42,16 +45,16 @@ public override void Cleanup()
public void UpdateSettlement(Transform parent)
{
TotalRevenue = $"총 수익 : {_settlementState.TotalRevenue.ToGold()}";
NormalCustomers = $"일반 손님 수 : {_settlementState.NormalCustomers}";
SpecialCustomers = $"스폐셜 손님 수 : {_settlementState.SpecialCustomers}";
TotalRevenue = $"총 수익 : {SettlementState.TotalRevenue.ToGold()}";
NormalCustomers = $"일반 손님 수 : {SettlementState.NormalCustomers}";
SpecialCustomers = $"스폐셜 손님 수 : {SettlementState.SpecialCustomers}";
Utils.DestroyAllChildren(parent);
int count = 0;
foreach (var soldCookingCount in _settlementState.SoldCookingCounts)
foreach (var soldCookingCount in SettlementState.SoldCookingCounts)
{
count++;
var instance = Instantiate(_settlementData.TextPrefab, parent);
var instance = Instantiate(SettlementData.TextPrefab, parent);
var textMeshProUGUI = instance.GetComponent<TextMeshProUGUI>();
var cookingName = LocalizationManager.Instance.GetName(soldCookingCount.Key);
textMeshProUGUI.text = $"판매된 메뉴{count} : {cookingName} {soldCookingCount.Value}";