using System;
using System.Collections.Generic;
namespace UnityEngine.XR.Content.Interaction
{
///
/// Use this object as a generic way to validate if an object can perform some action.
/// The check is done in the method.
/// This class is used in combination with a component.
///
///
///
[Serializable]
public class Lock
{
[SerializeField]
[Tooltip("The required keys to unlock this lock" +
"Create new keys by selecting \"Assets/Create/XR/Key Lock System/Key\"")]
List m_RequiredKeys;
///
/// Returns the required keys to unlock this lock.
///
public List requiredKeys => m_RequiredKeys;
///
/// Checks if the supplied keychain has all the required keys to open this lock.
///
/// The keychain to be checked.
/// True if the supplied keychain has all the required keys; false otherwise.
public bool CanUnlock(IKeychain keychain)
{
if (keychain == null)
return m_RequiredKeys.Count == 0;
foreach (var requiredKey in m_RequiredKeys)
{
if (requiredKey == null)
continue;
if (!keychain.Contains(requiredKey))
return false;
}
return true;
}
}
}