CapersProject/Assets/02.Scripts/DDD/Prop/Furniture/Fryer.cs

90 lines
2.8 KiB
C#
Raw Normal View History

2025-02-17 21:47:56 +00:00
using System;
using System.Threading.Tasks;
using DDD.ScriptableObjects;
using Sirenix.OdinInspector;
using UnityEngine;
namespace DDD.Tycoons
{
[Serializable]
2025-02-21 06:31:50 +00:00
public class Fryer : InteractionFurniture
2025-02-17 21:47:56 +00:00
{
[SerializeField]
private AnimationController _animationController;
[Title("연출")]
[SerializeField]
private Color _enableColor = Color.white;
[SerializeField]
private Color _disableColor = Color.gray;
private Material _instanceMaterial;
private CraftingTool _craftingTool = CraftingTool.Frying;
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.IsCookingFried = true;
2025-02-21 06:31:50 +00:00
_animationController.SetAnimationParameter(IsEnabledHash, true);
2025-02-17 21:47:56 +00:00
}
public override void CancelInteraction()
{
base.CancelInteraction();
GameManager.Instance.CurrentTycoonPlayer.IsCookingFried = false;
2025-02-21 06:31:50 +00:00
_animationController.SetAnimationParameter(IsEnabledHash, false);
2025-02-17 21:47:56 +00:00
}
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;
}
}
}
}