76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
using System;
|
|
using Fruitomation.Game.Items;
|
|
using Fruitomation.Global;
|
|
using UnityEngine;
|
|
|
|
namespace Fruitomation.Game
|
|
{
|
|
public class SlicerBuilding : Building
|
|
{
|
|
[Header("Slicer Specific Items")]
|
|
[SerializeField] private TriggerDetector TriggerDetector;
|
|
[SerializeField] private Animator SlicerAnimator;
|
|
|
|
private void Start()
|
|
{
|
|
TriggerDetector.SetAction(other =>
|
|
{
|
|
bool isItem = other.transform.parent.TryGetComponent(out ItemBehaviour item);
|
|
if (!isItem)
|
|
{
|
|
return;
|
|
}
|
|
|
|
item.CurrentType = item.CurrentType switch
|
|
{
|
|
ItemType.Apple => UpgradeManager.Is(BasicUpgrade.AppleSlices)
|
|
? ItemType.AppleSlices
|
|
: ItemType.Apple,
|
|
|
|
ItemType.Banana => UpgradeManager.Is(BasicUpgrade.BananaSlices)
|
|
? ItemType.BananaSlices
|
|
: ItemType.Banana,
|
|
|
|
ItemType.Kiwi => UpgradeManager.Is(BasicUpgrade.SlicedKiwi)
|
|
? ItemType.SlicedKiwi
|
|
: ItemType.Kiwi,
|
|
|
|
ItemType.Mango => UpgradeManager.Is(BasicUpgrade.MangoSlices)
|
|
? ItemType.MangoSlices
|
|
: ItemType.Mango,
|
|
|
|
ItemType.Durian => UpgradeManager.Is(BasicUpgrade.DurianSlices)
|
|
? ItemType.DurianSlices
|
|
: ItemType.Durian,
|
|
|
|
ItemType.BuddhasHand => UpgradeManager.Is(BasicUpgrade.BuddhasHandSlices)
|
|
? ItemType.BuddhasHandSlices
|
|
: ItemType.BuddhasHand,
|
|
|
|
var _ => item.CurrentType // Default
|
|
};
|
|
}, TriggerType.Enter);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (GameStateController.Is(GameState.Simulation))
|
|
{
|
|
if (SlicerAnimator.speed == 0)
|
|
{
|
|
SlicerAnimator.Play(0, 0, 0f); // Play from beginning
|
|
SlicerAnimator.speed = 1; // Playing
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
if (SlicerAnimator.speed != 0)
|
|
{
|
|
SlicerAnimator.Play(0, 0, 0f); // Jump back to default frame
|
|
SlicerAnimator.speed = 0; // Paused
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |