39 lines
1.1 KiB
C#
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)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|