Made presser properly press

This commit is contained in:
2026-04-22 00:11:59 +01:00
parent 289396c0ea
commit 6ed8a1fe85
3 changed files with 153 additions and 39 deletions

View File

@@ -1,7 +1,10 @@
using Fruitomation.Global;
using System.Collections.Generic;
using System.Linq;
using Fruitomation.Game.Items;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.Scripting;
using Fruitomation.Global;
using UnityEngine;
namespace Fruitomation.Game
{
@@ -11,7 +14,21 @@ namespace Fruitomation.Game
[SerializeField] private Animator PresserAnimator;
[SerializeField] private Collider2D TopCollider;
[SerializeField] private Collider2D BottomCollider;
[SerializeField] private TriggerDetector EffectTrigger;
private HashSet<GameObject> CurrentContainedObjects = new();
private void Awake()
{
EffectTrigger.SetAction(other => CurrentContainedObjects.Add(other.gameObject),
TriggerType.Enter
);
EffectTrigger.SetAction(other => CurrentContainedObjects.Remove(other.gameObject),
TriggerType.Exit
);
}
private void Update()
{
if (GameStateController.Is(GameState.Simulation))
@@ -33,37 +50,32 @@ namespace Fruitomation.Game
}
}
[Preserve, UsedImplicitly]
public void OpenTop()
{
Debug.Log(nameof(OpenTop));
TopCollider.enabled = false;
}
[Preserve, UsedImplicitly]
public void CloseTop()
{
Debug.Log(nameof(CloseTop));
TopCollider.enabled = true;
}
[Preserve, UsedImplicitly]
public void OpenBottom()
{
Debug.Log(nameof(OpenBottom));
BottomCollider.enabled = false;
}
[Preserve, UsedImplicitly]
public void CloseBottom()
{
Debug.Log(nameof(CloseBottom));
BottomCollider.enabled = true;
}
[Preserve, UsedImplicitly] public void OpenTop() => TopCollider.enabled = false;
[Preserve, UsedImplicitly] public void CloseTop() => TopCollider.enabled = true;
[Preserve, UsedImplicitly] public void OpenBottom() => BottomCollider.enabled = false;
[Preserve, UsedImplicitly] public void CloseBottom() => BottomCollider.enabled = true;
[Preserve, UsedImplicitly] public void Press()
{
Debug.Log("Presser Press");
GameObject[] gameObjects = CurrentContainedObjects.ToArray();
foreach (GameObject go in gameObjects)
{
bool isItem = go.transform.parent.TryGetComponent(out ItemBehaviour item);
if (!isItem)
{
return;
}
item.CurrentType = item.CurrentType switch
{
ItemType.Apple => ItemType.AppleJuice,
ItemType.Grape => ItemType.GrapeJuice,
ItemType.Kiwi => ItemType.KiwiJuice,
ItemType.PitayaSkin => ItemType.PitayaFoodDye,
var _ => item.CurrentType // Default
};
}
}
}
}