47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace DDD
|
|
{
|
|
public class TodayMenuInteractor : MonoBehaviour, IInteractableUi
|
|
{
|
|
private ItemSlotUi _slotUi;
|
|
private TodayMenuDataSo _todayMenuDataSo;
|
|
private TaskCompletionSource<bool> _isInitialized = new();
|
|
|
|
private void Awake()
|
|
{
|
|
_slotUi = GetComponent<ItemSlotUi>();
|
|
}
|
|
|
|
private async void Start()
|
|
{
|
|
_todayMenuDataSo = await AssetManager.LoadAsset<TodayMenuDataSo>(DataConstants.TodayMenuDataSo);
|
|
_isInitialized.SetResult(true);
|
|
}
|
|
|
|
public async void OnInteract()
|
|
{
|
|
await _isInitialized.Task;
|
|
|
|
string recipeId = _slotUi.Model.Id;
|
|
if (_todayMenuDataSo.Contains(recipeId))
|
|
{
|
|
_todayMenuDataSo.RemoveRecipe(recipeId);
|
|
_slotUi.ClearMark();
|
|
}
|
|
else
|
|
{
|
|
var recipe = DataManager.Instance.RecipeDataSo.GetDataById(recipeId);
|
|
|
|
bool added = recipe.RecipeType switch
|
|
{
|
|
RecipeType.FoodRecipe => _todayMenuDataSo.TryAddFoodRecipe(recipeId),
|
|
RecipeType.DrinkRecipe => _todayMenuDataSo.TryAddDrinkRecipe(recipeId),
|
|
_ => false
|
|
};
|
|
}
|
|
|
|
}
|
|
}
|
|
} |