71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class HandedInputSelector : MonoBehaviour
|
|
{
|
|
private OVRCameraRig m_CameraRig;
|
|
|
|
private OVRInputModule m_InputModule;
|
|
|
|
public bool forceRightHand;
|
|
|
|
public bool forceLeftHand;
|
|
|
|
public bool forceSecondaryController;
|
|
|
|
public bool automaticSwitch = true;
|
|
|
|
private void Start()
|
|
{
|
|
m_CameraRig = Object.FindObjectOfType<OVRCameraRig>();
|
|
m_InputModule = Object.FindObjectOfType<OVRInputModule>();
|
|
if (forceSecondaryController)
|
|
{
|
|
SetActiveController(VRControllersManager.Instance.GetSecondaryController());
|
|
}
|
|
else
|
|
{
|
|
SetActiveController(VRControllersManager.Instance.GetPrimaryController());
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (automaticSwitch)
|
|
{
|
|
if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.RTouch))
|
|
{
|
|
SetActiveController(OVRInput.Controller.RTouch);
|
|
}
|
|
else if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.LTouch))
|
|
{
|
|
SetActiveController(OVRInput.Controller.LTouch);
|
|
}
|
|
}
|
|
else if (forceSecondaryController)
|
|
{
|
|
SetActiveController(VRControllersManager.Instance.GetSecondaryController());
|
|
}
|
|
else
|
|
{
|
|
SetActiveController(VRControllersManager.Instance.GetPrimaryController());
|
|
}
|
|
}
|
|
|
|
public void SetActiveController(OVRInput.Controller c)
|
|
{
|
|
if (VRManager.IsVROn())
|
|
{
|
|
if ((bool)VRControllersManager.Instance && VRControllersManager.Instance.GetVRController(c) != null)
|
|
{
|
|
m_InputModule.rayTransform = VRControllersManager.Instance.GetVRController(c).pointerUITransform;
|
|
}
|
|
else if (!(m_CameraRig == null))
|
|
{
|
|
Transform rayTransform = ((c != OVRInput.Controller.LTouch) ? m_CameraRig.rightHandAnchor : m_CameraRig.leftHandAnchor);
|
|
m_InputModule.rayTransform = rayTransform;
|
|
}
|
|
}
|
|
}
|
|
}
|