Made presser properly press
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,15 @@ namespace Fruitomation.Game
|
||||
public enum TriggerType
|
||||
{
|
||||
Enter,
|
||||
Stay
|
||||
Stay,
|
||||
Exit
|
||||
}
|
||||
|
||||
public class TriggerDetector : MonoBehaviour
|
||||
{
|
||||
private Action<Collider2D> RegisteredActionStay;
|
||||
private Action<Collider2D> RegisteredActionEnter;
|
||||
|
||||
private TriggerType Type;
|
||||
private Action<Collider2D> RegisteredActionExit;
|
||||
|
||||
public void SetAction(Action<Collider2D> action, TriggerType type)
|
||||
{
|
||||
@@ -28,6 +28,10 @@ namespace Fruitomation.Game
|
||||
RegisteredActionEnter = action;
|
||||
return;
|
||||
|
||||
case TriggerType.Exit:
|
||||
RegisteredActionExit = action;
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
@@ -35,5 +39,6 @@ namespace Fruitomation.Game
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other) => RegisteredActionEnter?.Invoke(other);
|
||||
private void OnTriggerStay2D(Collider2D other) => RegisteredActionStay?.Invoke(other);
|
||||
private void OnTriggerExit2D(Collider2D other) => RegisteredActionExit?.Invoke(other);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user