mirror of
https://udrimavric.com/MAVRIC/Stratasys-450mc-VR.git
synced 2025-01-23 07:38:33 -05:00
44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
|
|
namespace Interactions
|
|
{
|
|
[DisallowMultipleComponent]
|
|
[RequireComponent(typeof(XRGrabInteractable))]
|
|
public class LockingInteractable : MonoBehaviour
|
|
{
|
|
[SerializeField] private InteractionLayerMask unlockedLayer;
|
|
[SerializeField] private bool isLocked = false;
|
|
|
|
private XRGrabInteractable grabInteractable;
|
|
|
|
public bool IsLocked => isLocked;
|
|
|
|
private void OnEnable()
|
|
{
|
|
TryGetComponent(out grabInteractable);
|
|
|
|
if (isLocked)
|
|
{
|
|
Lock();
|
|
return;
|
|
}
|
|
Unlock();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
// Add the unlocked layer to the interaction layer mask
|
|
grabInteractable.interactionLayerMask |= unlockedLayer;
|
|
isLocked = false;
|
|
}
|
|
|
|
public void Lock()
|
|
{
|
|
// Remove the unlocked layer from the interaction layer mask
|
|
grabInteractable.interactionLayerMask &= ~unlockedLayer;
|
|
isLocked = true;
|
|
}
|
|
}
|
|
} |