1
0
forked from cgvr/DeltaVR

deltavr multiplayer 2.0

This commit is contained in:
Toomas Tamm
2023-05-08 15:56:10 +03:00
parent 978809a002
commit 07b9b9e2f4
10937 changed files with 2968397 additions and 1521012 deletions

View File

@@ -0,0 +1,42 @@
using Unity.XR.CoreUtils;
using UnityEngine.XR.Interaction.Toolkit;
namespace UnityEngine.XR.Content.Interaction
{
/// <summary>
/// Add this to your interactable to make it snap to the source of the XR Ray Interactor
/// instead of staying at a distance. Has a similar outcome as enabling Force Grab.
/// </summary>
public class RayAttachModifier : MonoBehaviour
{
IXRSelectInteractable m_SelectInteractable;
protected void OnEnable()
{
m_SelectInteractable = GetComponent<IXRSelectInteractable>();
if (m_SelectInteractable as Object == null)
{
Debug.LogError($"Ray Attach Modifier missing required Select Interactable on {name}", this);
return;
}
m_SelectInteractable.selectEntered.AddListener(OnSelectEntered);
}
protected void OnDisable()
{
if (m_SelectInteractable as Object != null)
m_SelectInteractable.selectEntered.RemoveListener(OnSelectEntered);
}
void OnSelectEntered(SelectEnterEventArgs args)
{
if (!(args.interactorObject is XRRayInteractor))
return;
var attachTransform = args.interactorObject.GetAttachTransform(m_SelectInteractable);
var originalAttachPose = args.interactorObject.GetLocalAttachPoseOnSelect(m_SelectInteractable);
attachTransform.SetLocalPose(originalAttachPose);
}
}
}