57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace Interaction.Conditions
|
||
|
|
{
|
||
|
|
public class UnlockStatesOnInteractSucceeded : InteractConditionBehaviour
|
||
|
|
{
|
||
|
|
[SerializeField] private InteractUnlockState selfState;
|
||
|
|
[SerializeField] private bool unlockSelf = true;
|
||
|
|
[SerializeField] private InteractUnlockState[] targetStates;
|
||
|
|
|
||
|
|
[Header("Behavior")]
|
||
|
|
[SerializeField] private bool onlyOnce = true;
|
||
|
|
[SerializeField] private bool triggered;
|
||
|
|
|
||
|
|
[Header("Debug")]
|
||
|
|
[SerializeField] private bool debugLog;
|
||
|
|
|
||
|
|
public override bool CanInteract(GameObject interactor, out string failReason)
|
||
|
|
{
|
||
|
|
failReason = null;
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void OnInteractSucceeded(GameObject interactor)
|
||
|
|
{
|
||
|
|
if (onlyOnce && triggered) return;
|
||
|
|
|
||
|
|
if (unlockSelf)
|
||
|
|
{
|
||
|
|
var state = selfState != null ? selfState : GetComponentInParent<InteractUnlockState>();
|
||
|
|
if (state != null) state.SetUnlocked(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (targetStates != null)
|
||
|
|
{
|
||
|
|
for (int i = 0; i < targetStates.Length; i++)
|
||
|
|
{
|
||
|
|
var state = targetStates[i];
|
||
|
|
if (state == null) continue;
|
||
|
|
state.SetUnlocked(true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
triggered = true;
|
||
|
|
|
||
|
|
if (debugLog)
|
||
|
|
{
|
||
|
|
Debug.Log(
|
||
|
|
$"[UnlockStatesOnInteractSucceeded] Triggered on '{name}' " +
|
||
|
|
$"unlockSelf={unlockSelf} targets={(targetStates == null ? 0 : targetStates.Length)}",
|
||
|
|
this);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|