Initial commit

This commit is contained in:
Thorbjoern
2025-05-26 00:46:28 +02:00
commit e5bca03433
3896 changed files with 1434297 additions and 0 deletions
@@ -0,0 +1,16 @@
namespace UnityEngine.XR.Content.Interaction
{
/// <summary>
/// Interface to implement for objects that hold a set of <c>Key</c>s
/// </summary>
public interface IKeychain
{
/// <summary>
/// This callback is used to check if this keychain has a specific <c>Key</c>
/// <see cref="Lock"/>
/// </summary>
/// <param name="key">the key to be checked</param>
/// <returns>True if this keychain has the supplied key; false otherwise</returns>
bool Contains(Key key);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3273498567e6fc4b944c2985269269d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
namespace UnityEngine.XR.Content.Interaction
{
/// <summary>
/// An asset that represents a key. Used to check if an object can perform some action
/// (<see cref="XRLockSocketInteractor"/> and <see cref="Keychain"/>)
/// </summary>
[CreateAssetMenuAttribute(menuName = "XR/Key Lock System/Key")]
public class Key : ScriptableObject
{ }
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4e629f4cfca91134e86ae027aaa5d4eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,73 @@
using System.Collections.Generic;
namespace UnityEngine.XR.Content.Interaction
{
/// <summary>
/// A generic Keychain component that holds the <see cref="Key"/>s to open a <see cref="Lock"/>.
/// Attach a Keychain component to an Interactable and assign to it the same Keys of an <see cref="XRLockSocketInteractor"/>
/// or an <see cref="XRLockGridSocketInteractor"/> to open (or interact with) them.
/// </summary>
[DisallowMultipleComponent]
public class Keychain : MonoBehaviour, IKeychain
{
[SerializeField]
[Tooltip("The keys on this keychain" +
"Create new keys by selecting \"Assets/Create/XR/Key Lock System/Key\"")]
List<Key> m_Keys;
HashSet<int> m_KeysHashSet = new HashSet<int>();
void Awake()
{
RepopulateHashSet();
}
void OnValidate()
{
// A key was added through the inspector while the game was running?
if (Application.isPlaying && m_Keys.Count != m_KeysHashSet.Count)
RepopulateHashSet();
}
void RepopulateHashSet()
{
m_KeysHashSet.Clear();
foreach (var key in m_Keys)
{
if (key != null)
m_KeysHashSet.Add(key.GetInstanceID());
}
}
/// <summary>
/// Adds the supplied key to this keychain
/// </summary>
/// <param name="key">The key to be added to the keychain</param>
public void AddKey(Key key)
{
if (key == null || Contains(key))
return;
m_Keys.Add(key);
m_KeysHashSet.Add(key.GetInstanceID());
}
/// <summary>
/// Adds the supplied key from this keychain
/// </summary>
/// <param name="key">The key to be removed from the keychain</param>
public void RemoveKey(Key key)
{
m_Keys.Remove(key);
if (key != null)
m_KeysHashSet.Remove(key.GetInstanceID());
}
/// <inheritdoc />
public bool Contains(Key key)
{
return key != null && m_KeysHashSet.Contains(key.GetInstanceID());
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 505599121cd7c2d4d87a596056b0142b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
namespace UnityEngine.XR.Content.Interaction
{
/// <summary>
/// Use this object as a generic way to validate if an object can perform some action.
/// The check is done in the <see cref="CanUnlock"/> method.
/// This class is used in combination with a <see cref="Keychain"/> component.
/// </summary>
/// <seealso cref="XRLockSocketInteractor"/>
/// <seealso cref="XRLockGridSocketInteractor"/>
[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<Key> m_RequiredKeys;
/// <summary>
/// Returns the required keys to unlock this lock.
/// </summary>
public List<Key> requiredKeys => m_RequiredKeys;
/// <summary>
/// Checks if the supplied keychain has all the required keys to open this lock.
/// </summary>
/// <param name="keychain">The keychain to be checked.</param>
/// <returns>True if the supplied keychain has all the required keys; false otherwise.</returns>
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;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d479cceb8cf26842888dcaf56f46717
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: