using System; using System.Threading.Tasks; using DDD.ScriptableObjects; using Sirenix.OdinInspector; using UnityEngine; namespace DDD.Tycoons { [Serializable] public class Pot : InteractionFurniture { [SerializeField] private AnimationController _animationController; [Title("연출")] [SerializeField] private Color _enableColor = Color.white; [SerializeField] private Color _disableColor = Color.gray; private Material _instanceMaterial; private CraftingTool _craftingTool = CraftingTool.Pot; private const string IsEnabledHash = "isEnabled"; protected override void Start() { base.Start(); HoldingAction = SuccessHoldingAction; _instanceMaterial = VisualLook.material; VisualLook.material = Instantiate(_instanceMaterial); EventManager.OnChangedCraftingTool += ChangeColor; } protected override void OnDestroy() { base.OnDestroy(); EventManager.OnChangedCraftingTool -= ChangeColor; } public override void Interaction() { base.Interaction(); GameManager.Instance.CurrentTycoonPlayer.IsCookingStew = true; _animationController.SetAnimationParameter(IsEnabledHash, true); } public override void CancelInteraction() { base.CancelInteraction(); GameManager.Instance.CurrentTycoonPlayer.IsCookingStew = false; _animationController.SetAnimationParameter(IsEnabledHash, false); } public override bool CanInteraction() { CraftRecipeData playerCraftRecipeData = CurrentTycoonPlayer.TycoonPickupHandler.CurrentCraftRecipeData; if (playerCraftRecipeData == null || playerCraftRecipeData.CraftingToolQueue.Count <= 0) return false; CraftingTool playerCraftingTool = playerCraftRecipeData.CraftingToolQueue.Peek(); return IsOpened && playerCraftingTool == _craftingTool; } private void SuccessHoldingAction() { CurrentTycoonPlayer.TycoonPickupHandler.InteractionCraftingTool(); CancelInteraction(); } private async void ChangeColor(CraftingTool? playerCraftingTool) { await Task.Delay(100); if (playerCraftingTool == null) { VisualLook.material.color = _enableColor; } else { VisualLook.material.color = (CraftingTool)playerCraftingTool == _craftingTool ? _enableColor : _disableColor; } } } }