73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace DDD
|
|
{
|
|
public enum TodayMenuEventType
|
|
{
|
|
None = 0,
|
|
Add,
|
|
Remove
|
|
}
|
|
|
|
public class TodayMenuInteractor : MonoBehaviour, IInteractableUi
|
|
{
|
|
private IInventorySlotUi _inventorySlotUi;
|
|
private RestaurantManagementSo _restaurantManagementSo;
|
|
private TaskCompletionSource<bool> _isInitialized = new();
|
|
private TodayMenuEventType _todayMenuEventType = TodayMenuEventType.None;
|
|
|
|
private void Awake()
|
|
{
|
|
_inventorySlotUi = GetComponent<IInventorySlotUi>();
|
|
}
|
|
|
|
public async void Initialize(TodayMenuEventType todayMenuEventType)
|
|
{
|
|
_todayMenuEventType = todayMenuEventType;
|
|
|
|
_restaurantManagementSo = await AssetManager.LoadAsset<RestaurantManagementSo>(DataConstants.RestaurantManagementSo);
|
|
_isInitialized.SetResult(true);
|
|
}
|
|
|
|
public async void OnInteract()
|
|
{
|
|
await _isInitialized.Task;
|
|
|
|
switch (_todayMenuEventType)
|
|
{
|
|
case TodayMenuEventType.Add:
|
|
OnAdded();
|
|
break;
|
|
case TodayMenuEventType.Remove:
|
|
OnRemoved();
|
|
break;
|
|
case TodayMenuEventType.None:
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
}
|
|
|
|
private void OnAdded()
|
|
{
|
|
if (_inventorySlotUi.CanCraft() == false)
|
|
{
|
|
var evt = GameEvents.RequestShowGlobalMessageEvent;
|
|
// TODO : 테스트용 메세지 추후 삭제 및 변경
|
|
evt.NewMessageKey = "today_menu_added_error_message_001";
|
|
evt.FadeDuration = 0.5f;
|
|
evt.ShowDuration = 1f;
|
|
EventBus.Broadcast(evt);
|
|
return;
|
|
}
|
|
|
|
_restaurantManagementSo.TryAddTodayMenu(_inventorySlotUi);
|
|
}
|
|
|
|
private void OnRemoved()
|
|
{
|
|
_restaurantManagementSo.TryRemoveTodayMenu(_inventorySlotUi);
|
|
}
|
|
}
|
|
} |