Files
Echo/Assets/_Project/Scripts/Interaction/Conditions/RequireUnlockedInteractCondition.cs
T
2026-07-08 20:42:51 +08:00

39 lines
1.1 KiB
C#

using UnityEngine;
namespace Interaction.Conditions
{
public class RequireUnlockedInteractCondition : InteractConditionBehaviour
{
[SerializeField] private InteractUnlockState unlockState;
[Header("失败提示")]
[SerializeField] private string failReason = "尚未解锁";
[Header("容错")]
[SerializeField] private bool allowIfUnlockStateMissing;
public override bool CanInteract(GameObject interactor, out string reason)
{
reason = null;
var state = unlockState != null ? unlockState : GetComponentInParent<InteractUnlockState>();
if (state == null)
{
if (allowIfUnlockStateMissing) return true;
reason = string.IsNullOrWhiteSpace(failReason) ? "尚未解锁" : failReason;
return false;
}
if (state.IsUnlocked) return true;
reason = string.IsNullOrWhiteSpace(failReason) ? "尚未解锁" : failReason;
return false;
}
public override void OnInteractSucceeded(GameObject interactor)
{
}
}
}