using BlueWater.Items; using Sirenix.OdinInspector; using UnityEngine; namespace BlueWater.Players.Tycoons { public class TycoonFoodHandler : MonoBehaviour { [SerializeField] private SpriteRenderer _foodRenderer; [SerializeField] private bool _isCarriedFood; private ItemData _currentFoodData; private ItemManager _itemManager; private void Awake() { InitializeComponents(); } private void Start() { _itemManager = ItemManager.Instance; } [Button("컴포넌트 초기화")] private void InitializeComponents() { _foodRenderer = transform.Find("VisualLook/Food").GetComponent(); } public void CarryFood(int foodIdx) { if (_isCarriedFood) { Debug.Log("이미 음식을 들고 있습니다."); return; } _currentFoodData = _itemManager.GetItemDataByIdx(foodIdx); if (_currentFoodData == null) { Debug.LogError($"{foodIdx} 해당 음식을 등록할 수 없습니다."); return; } var itemSprite = _currentFoodData.Sprite; if (!itemSprite) { Debug.LogWarning($"{itemSprite} 해당 음식의 이미지가 없습니다."); } _foodRenderer.sprite = itemSprite; _isCarriedFood = true; } public void GiveFood() { if (!_isCarriedFood || _currentFoodData == null) { Debug.Log("들고있는 음식이 없거나, 현재 음식 데이터가 비어있습니다."); return; } _currentFoodData = null; _foodRenderer.sprite = null; _isCarriedFood = false; } public void DiscardFood() { if (!_isCarriedFood || _currentFoodData == null) { Debug.Log("들고있는 음식이 없거나, 현재 음식 데이터가 비어있습니다."); return; } _currentFoodData = null; _foodRenderer.sprite = null; _isCarriedFood = false; } public ItemData GetCurrentFoodData() => _currentFoodData; } }