Files
Echo/Assets/_Project/Scripts/Interaction/Conditions/InteractCountAccumulator.cs
T

41 lines
1.2 KiB
C#
Raw Normal View History

2026-07-08 19:53:15 +08:00
using UnityEngine;
namespace Interaction.Conditions
{
public class InteractCountAccumulator : InteractConditionBehaviour
{
[SerializeField] private Interaction.InteractCountThresholdSystem targetSystem;
[SerializeField] private int addAmount = 1;
[SerializeField] private bool autoFindTargetSystemIfNull = true;
private bool hadTargetSystemAtEnable = false;
private void OnEnable()
{
hadTargetSystemAtEnable = targetSystem != null;
}
public override bool CanInteract(GameObject interactor, out string failReason)
{
failReason = null;
return true;
}
public override void OnInteractSucceeded(GameObject interactor)
{
if (addAmount <= 0) return;
if (targetSystem == null)
{
if (hadTargetSystemAtEnable) return;
if (!autoFindTargetSystemIfNull) return;
targetSystem = FindObjectOfType<Interaction.InteractCountThresholdSystem>(true);
}
if (targetSystem == null) return;
targetSystem.Add(addAmount);
}
}
}