41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
|
|
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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|