Data로직 수정으로 불필요한 Task 정리

This commit is contained in:
NTG 2025-08-17 15:43:02 +09:00
parent 2f2226e3d4
commit 2c3f257353
19 changed files with 75 additions and 97 deletions

Binary file not shown.

View File

@ -22,7 +22,8 @@ public class CameraManager : Singleton<CameraManager>, IManager
private void OnDestroy()
{
foreach (var cameraGameObject in _cameraGameObjects.Values)
var snapshot = new List<CameraGameObject>(_cameraGameObjects.Values);
foreach (var cameraGameObject in snapshot)
{
if (cameraGameObject)
{

View File

@ -20,9 +20,9 @@ protected override void Update()
base.Update();
var currentSelectedGameObject = EventSystem.current.currentSelectedGameObject;
if (!currentSelectedGameObject || currentSelectedGameObject.activeInHierarchy == false)
if (currentSelectedGameObject == null || currentSelectedGameObject.activeInHierarchy == false)
{
if (!GetInitialSelected()) return;
if (GetInitialSelected() == null) return;
EventSystem.current.SetSelectedGameObject(GetInitialSelected());
}

View File

@ -1,13 +1,12 @@
using System.Threading.Tasks;
using Mono.Cecil;
using UnityEngine;
namespace DDD
{
public class InventorySlotUiStrategy : IItemSlotUiStrategy
{
public string AnimatorControllerKey => "InventorySlotUi";
public Task Setup(ItemSlotUi ui, ItemViewModel model)
public void Setup(ItemSlotUi ui, ItemViewModel model)
{
if (InventoryManager.Instance.ContainInventoryItem(model.Id))
{
@ -16,7 +15,7 @@ public Task Setup(ItemSlotUi ui, ItemViewModel model)
ui.HideMark();
ui.SetButtonInteractable(true);
return Task.CompletedTask;
return;
}
// TODO : 임시 초기화 값
@ -37,13 +36,11 @@ public Task Setup(ItemSlotUi ui, ItemViewModel model)
ui.HideCountText();
ui.HideMark();
ui.SetButtonInteractable(false);
return Task.CompletedTask;
}
public async Task<RuntimeAnimatorController> GetAnimatorController()
public RuntimeAnimatorController GetAnimatorController()
{
return await AssetManager.LoadAsset<RuntimeAnimatorController>(AnimatorControllerKey);
return RestaurantDataSo.instance.ManagementData.InventorySlotUiAnimatorController;
}
public void OnInventoryChanged(ItemSlotUi ui)

View File

@ -36,7 +36,7 @@ private void OnDisable()
EventBus.Unregister<TodayMenuRemovedEvent>(this);
}
public async Task Initialize()
public void Initialize()
{
restaurantManagementStateSo = RestaurantState.instance.ManagementState;
restaurantManagementDataSo = RestaurantDataSo.instance.ManagementData;
@ -51,19 +51,19 @@ public async Task Initialize()
{
var itemSlotUi = Instantiate(restaurantManagementDataSo.ItemSlotUiPrefab, _slotParent);
var slot = itemSlotUi.GetComponent<ItemSlotUi>();
await slot.Initialize(model, new InventorySlotUiStrategy());
slot.Initialize(model, new InventorySlotUiStrategy());
itemSlotUi.name = ItemSlotUiName + model.Id;
var interactor = itemSlotUi.GetComponent<ItemSlotInteractor>();
if (model.ItemType == ItemType.Recipe)
{
await interactor.Initialize(TodayMenuEventType.Add, new TodayMenuInteractorStrategy());
interactor.Initialize(TodayMenuEventType.Add, new TodayMenuInteractorStrategy());
}
else
{
if (DataManager.Instance.GetDataSo<CookwareDataSo>().TryGetDataById(model.Id, out var cookwareData))
{
await interactor.Initialize(TodayMenuEventType.Add, new TodayCookwareInteractorStrategy());
interactor.Initialize(TodayMenuEventType.Add, new TodayCookwareInteractorStrategy());
}
}

View File

@ -23,32 +23,28 @@ public class ItemDetailView : MonoBehaviour, IEventHandler<ItemSlotSelectedEvent
[SerializeField] private RectTransform _tasteHashTagContent2;
private RestaurantManagementDataSo restaurantManagementDataSo;
private RestaurantManagementStateSo restaurantManagementStateSo;
private List<TasteHashTagSlotUi> _tasteHashTagSlotUis = new();
private ItemViewModel _currentItemViewModel;
private TaskCompletionSource<bool> _isInitialized = new();
private const string CookwareDetailPanel = "CookwareDetailPanel";
private const string IngredientDetailPanel = "IngredientDetailPanel";
private const string RecipeDetailPanel = "RecipeDetailPanel";
private async void Start()
private void Start()
{
restaurantManagementDataSo = RestaurantDataSo.instance.ManagementData;
restaurantManagementStateSo = RestaurantState.instance.ManagementState;
Debug.Assert(restaurantManagementDataSo != null, "RestaurantManagementSo is null");
Debug.Assert(restaurantManagementStateSo != null, "RestaurantManagementSo is null");
_nameLabel.text = string.Empty;
_descriptionLabel.text = string.Empty;
_cookwareImage.sprite = null;
_isInitialized.SetResult(true);
}
private void OnEnable()
{
if (restaurantManagementDataSo == null)
{
restaurantManagementDataSo = RestaurantDataSo.instance.ManagementData;
}
EventBus.Register<ItemSlotSelectedEvent>(this);
}
@ -62,10 +58,8 @@ public void Invoke(ItemSlotSelectedEvent evt)
Show(evt.Model);
}
public async void Show(ItemViewModel model)
public void Show(ItemViewModel model)
{
await _isInitialized.Task;
_currentItemViewModel = model;
if (_currentItemViewModel == null) return;

View File

@ -4,6 +4,6 @@ namespace DDD
{
public interface IInteractableUi
{
Task OnInteract();
void OnInteract();
}
}

View File

@ -5,8 +5,7 @@ namespace DDD
{
public interface IItemSlotUiStrategy
{
string AnimatorControllerKey { get; }
Task Setup(ItemSlotUi ui, ItemViewModel model);
Task<RuntimeAnimatorController> GetAnimatorController();
void Setup(ItemSlotUi ui, ItemViewModel model);
RuntimeAnimatorController GetAnimatorController();
}
}

View File

@ -16,7 +16,7 @@ public class ItemSlotInteractor : MonoBehaviour, IInteractableUi
{
private ItemSlotUi _itemSlotUi;
private RestaurantManagementStateSo restaurantManagementStateSo;
private TaskCompletionSource<bool> _isInitialized = new();
private TodayMenuEventType _todayMenuEventType = TodayMenuEventType.None;
public IItemSlotInteractorStrategy Strategy { get; private set; }
@ -26,19 +26,16 @@ private void Awake()
_itemSlotUi = GetComponent<ItemSlotUi>();
}
public async Task Initialize(TodayMenuEventType todayMenuEventType, IItemSlotInteractorStrategy strategy)
public void Initialize(TodayMenuEventType todayMenuEventType, IItemSlotInteractorStrategy strategy)
{
_todayMenuEventType = todayMenuEventType;
Strategy = strategy;
restaurantManagementStateSo = RestaurantState.instance.ManagementState;
_isInitialized.SetResult(true);
}
public async Task OnInteract()
public void OnInteract()
{
await _isInitialized.Task;
switch (_todayMenuEventType)
{
case TodayMenuEventType.Add:

View File

@ -19,14 +19,14 @@ public class ItemSlotUi : MonoBehaviour, ISelectHandler, IAutoScrollItem
[field: SerializeField] public ItemViewModel Model { get; private set; }
public IItemSlotUiStrategy Strategy { get; private set; }
public async Task Initialize(ItemViewModel model, IItemSlotUiStrategy strategy)
public void Initialize(ItemViewModel model, IItemSlotUiStrategy strategy)
{
Model = model;
Strategy = strategy;
var controller = await strategy.GetAnimatorController();
var controller = strategy.GetAnimatorController();
_animator.runtimeAnimatorController = controller;
_ = Strategy.Setup(this, model);
Strategy.Setup(this, model);
}
public void SetIcon(Sprite sprite) => _icon.sprite = sprite;

View File

@ -81,11 +81,11 @@ protected override GameObject GetInitialSelected()
return null;
}
public async override void Open(OpenPopupUiEvent evt)
public override void Open(OpenPopupUiEvent evt)
{
base.Open(evt);
await _inventoryView.Initialize();
_inventoryView.Initialize();
// 각 그룹별로 허용된 카테고리 설정
SetupCategoryTabs();

View File

@ -113,11 +113,10 @@ private void SetActiveContents(bool isActive)
}
}
public Task OnInteract()
public void OnInteract()
{
_onSelected?.Invoke(_tabButtonValue);
OnTabClicked?.Invoke(_tabButtonValue);
return Task.CompletedTask;
}
}
}

View File

@ -6,18 +6,15 @@ namespace DDD
public class TodayMenuSlotUiStrategy : IItemSlotUiStrategy
{
private readonly RecipeType _recipeType;
private RestaurantManagementStateSo restaurantManagementStateSo;
public string AnimatorControllerKey => "TodayMenuSlotUi";
public TodayMenuSlotUiStrategy(RecipeType recipeType)
{
_recipeType = recipeType;
}
public async Task Setup(ItemSlotUi ui, ItemViewModel model)
public void Setup(ItemSlotUi ui, ItemViewModel model)
{
restaurantManagementStateSo = RestaurantState.instance.ManagementState;
var restaurantManagementStateSo = RestaurantState.instance.ManagementState;
if (model == null)
{
@ -54,9 +51,9 @@ public async Task Setup(ItemSlotUi ui, ItemViewModel model)
ui.SetButtonInteractable(true);
}
public async Task<RuntimeAnimatorController> GetAnimatorController()
public RuntimeAnimatorController GetAnimatorController()
{
return await AssetManager.LoadAsset<RuntimeAnimatorController>(AnimatorControllerKey);
return RestaurantDataSo.instance.ManagementData.TodayMenuSlotUiAnimatorController;
}
}
}

View File

@ -17,7 +17,7 @@ public class TodayMenuView : MonoBehaviour, IEventHandler<TodayMenuAddedEvent>,
private void Start()
{
_ = Initialize();
Initialize();
}
private void OnDestroy()
@ -26,11 +26,10 @@ private void OnDestroy()
EventBus.Unregister<TodayMenuRemovedEvent>(this);
}
private async Task Initialize()
private void Initialize()
{
restaurantManagementStateSo = RestaurantState.instance.ManagementState;
restaurantManagementDataSo = RestaurantDataSo.instance.ManagementData;
Debug.Assert(restaurantManagementStateSo != null, "_restaurantManagementSo != null");
foreach (Transform child in _todayFoodContent)
{
@ -43,9 +42,9 @@ private async Task Initialize()
{
var go = Instantiate(restaurantManagementDataSo.ItemSlotUiPrefab, _todayFoodContent);
var slot = go.GetComponent<ItemSlotUi>();
await slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayMenuInteractorStrategy());
itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayMenuInteractorStrategy());
_foodSlots.Add(slot);
}
@ -61,9 +60,9 @@ private async Task Initialize()
{
var go = Instantiate(restaurantManagementDataSo.ItemSlotUiPrefab, _todayDrinkContent);
var slot = go.GetComponent<ItemSlotUi>();
await slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
slot.Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayMenuInteractorStrategy());
itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayMenuInteractorStrategy());
_drinkSlots.Add(slot);
}
@ -93,14 +92,14 @@ private void UpdateView()
var model = ItemViewModelFactory.CreateByItemId(foodRecipeIdCountPair.Key);
var foodSlot = _foodSlots[foodIndex];
_ = foodSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
foodSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
foodSlot.Model.SetCount(foodRecipeIdCountPair.Value);
foodIndex++;
}
for (int i = foodIndex; i < _foodSlots.Count; i++)
{
_ = _foodSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
_foodSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.FoodRecipe));
}
int drinkIndex = 0;
@ -110,14 +109,14 @@ private void UpdateView()
var model = ItemViewModelFactory.CreateByItemId(drinkRecipeIdCountPair.Key);
var drinkSlot = _drinkSlots[drinkIndex];
_ = drinkSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
drinkSlot.Initialize(model, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
drinkSlot.Model.SetCount(drinkRecipeIdCountPair.Value);
drinkIndex++;
}
for (int i = drinkIndex; i < _drinkSlots.Count; i++)
{
_ = _drinkSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
_drinkSlots[i].Initialize(null, new TodayMenuSlotUiStrategy(RecipeType.DrinkRecipe));
}
}
}

View File

@ -5,11 +5,7 @@ namespace DDD
{
public class TodayCookwareSlotUiStrategy : IItemSlotUiStrategy
{
private RestaurantManagementStateSo restaurantManagementStateSo;
public string AnimatorControllerKey => "TodayMenuSlotUi";
public Task Setup(ItemSlotUi ui, ItemViewModel model)
public void Setup(ItemSlotUi ui, ItemViewModel model)
{
if (model == null)
{
@ -18,20 +14,18 @@ public Task Setup(ItemSlotUi ui, ItemViewModel model)
ui.HideMark();
ui.SetButtonInteractable(false);
return Task.CompletedTask;
return;
}
ui.SetIcon(model.ItemSprite);
ui.HideCountText();
ui.ShowMark(DataManager.Instance.GetSprite(SpriteConstants.CheckNoSpriteKey)); // TODO : 추후에 장비와 매칭
ui.SetButtonInteractable(true);
return Task.CompletedTask;
}
public async Task<RuntimeAnimatorController> GetAnimatorController()
public RuntimeAnimatorController GetAnimatorController()
{
return await AssetManager.LoadAsset<RuntimeAnimatorController>(AnimatorControllerKey);
return RestaurantDataSo.instance.ManagementData.TodayMenuSlotUiAnimatorController;
}
}
}

View File

@ -17,7 +17,7 @@ public class TodayRestaurantStateView : MonoBehaviour, IEventHandler<TodayMenuAd
private void Start()
{
_ = Initialize();
Initialize();
}
private void OnDestroy()
@ -26,11 +26,10 @@ private void OnDestroy()
EventBus.Unregister<TodayMenuRemovedEvent>(this);
}
private async Task Initialize()
private void Initialize()
{
restaurantManagementStateSo = RestaurantState.instance.ManagementState;
restaurantManagementDataSo = RestaurantDataSo.instance.ManagementData;
Debug.Assert(restaurantManagementStateSo != null, "_restaurantManagementSo != null");
foreach (Transform child in _todayWorkerContent)
{
@ -43,9 +42,9 @@ private async Task Initialize()
{
var go = Instantiate(restaurantManagementDataSo.ItemSlotUiPrefab, _todayWorkerContent);
var slot = go.GetComponent<ItemSlotUi>();
await slot.Initialize(null, new TodayWorkerSlotUiStrategy());
slot.Initialize(null, new TodayWorkerSlotUiStrategy());
var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayCookwareInteractorStrategy());
itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayCookwareInteractorStrategy());
_workerSlots.Add(slot);
}
@ -60,9 +59,9 @@ private async Task Initialize()
{
var go = Instantiate(restaurantManagementDataSo.ItemSlotUiPrefab, _todayCookwareContent);
var slot = go.GetComponent<ItemSlotUi>();
await slot.Initialize(null, new TodayCookwareSlotUiStrategy());
slot.Initialize(null, new TodayCookwareSlotUiStrategy());
var itemSlotInteractor = go.GetComponent<ItemSlotInteractor>();
await itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayCookwareInteractorStrategy());
itemSlotInteractor.Initialize(TodayMenuEventType.Remove, new TodayCookwareInteractorStrategy());
_cookwareSlots.Add(slot);
}
@ -92,14 +91,14 @@ private void UpdateView()
var model = ItemViewModelFactory.CreateByItemId(workerKey);
var newWorkerSlot = _workerSlots[workerIndex];
_ = newWorkerSlot.Initialize(model, new TodayWorkerSlotUiStrategy());
newWorkerSlot.Initialize(model, new TodayWorkerSlotUiStrategy());
newWorkerSlot.Model.SetCount(1);
workerIndex++;
}
for (int i = workerIndex; i < _workerSlots.Count; i++)
{
_ = _workerSlots[i].Initialize(null, new TodayWorkerSlotUiStrategy());
_workerSlots[i].Initialize(null, new TodayWorkerSlotUiStrategy());
}
int cookwareIndex = 0;
@ -109,14 +108,14 @@ private void UpdateView()
var model = ItemViewModelFactory.CreateByItemId(cookwareKey);
var newCookwareSlot = _cookwareSlots[cookwareIndex];
_ = newCookwareSlot.Initialize(model, new TodayCookwareSlotUiStrategy());
newCookwareSlot.Initialize(model, new TodayCookwareSlotUiStrategy());
newCookwareSlot.Model.SetCount(1);
cookwareIndex++;
}
for (int i = cookwareIndex; i < _cookwareSlots.Count; i++)
{
_ = _cookwareSlots[i].Initialize(null, new TodayCookwareSlotUiStrategy());
_cookwareSlots[i].Initialize(null, new TodayCookwareSlotUiStrategy());
}
}
}

View File

@ -1,15 +1,12 @@
using System.Threading.Tasks;
using Unity.VisualScripting.Antlr3.Runtime;
using UnityEngine;
namespace DDD
{
public class TodayWorkerSlotUiStrategy : IItemSlotUiStrategy
{
private RestaurantManagementStateSo restaurantManagementStateSo;
public string AnimatorControllerKey => "TodayMenuSlotUi";
public Task Setup(ItemSlotUi ui, ItemViewModel model)
public void Setup(ItemSlotUi ui, ItemViewModel model)
{
if (model == null)
{
@ -18,20 +15,18 @@ public Task Setup(ItemSlotUi ui, ItemViewModel model)
ui.HideMark();
ui.SetButtonInteractable(false);
return Task.CompletedTask;
return;
}
ui.SetIcon(model.ItemSprite);
ui.HideCountText();
ui.ShowMark(DataManager.Instance.GetSprite(SpriteConstants.CheckNoSpriteKey)); // TODO : 추후에 장비와 매칭
ui.SetButtonInteractable(true);
return Task.CompletedTask;
}
public async Task<RuntimeAnimatorController> GetAnimatorController()
public RuntimeAnimatorController GetAnimatorController()
{
return await AssetManager.LoadAsset<RuntimeAnimatorController>(AnimatorControllerKey);
return RestaurantDataSo.instance.ManagementData.TodayMenuSlotUiAnimatorController;
}
}
}

View File

@ -11,5 +11,8 @@ public class RestaurantManagementDataSo : ScriptableObject
public Material FoodTasteMaterial;
public Material DrinkTasteMateria;
public RuntimeAnimatorController TodayMenuSlotUiAnimatorController;
public RuntimeAnimatorController InventorySlotUiAnimatorController;
}
}

View File

@ -33,6 +33,10 @@ public async Task LoadData()
PlayerData = playerHandle.Result;
ManagementData = managementHandle.Result;
Debug.Assert(PlayerData != null, "PlayerData is null");
Debug.Assert(ManagementData != null, "ManagementData is null");
_isLoaded = true;
}