74 lines
1.6 KiB
C#
74 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
//using UnityEditor.Animations;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem.XR;
|
|
using UnityEngine.XR;
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
using XRController = UnityEngine.XR.Interaction.Toolkit.XRController;
|
|
|
|
public class XR_Ray_Controller : MonoBehaviour
|
|
{
|
|
public XRController controller;
|
|
public XRInteractorLineVisual ray;
|
|
//public GameObject reticle;
|
|
|
|
[SerializeField]
|
|
public XRNode xrNode = XRNode.LeftHand;
|
|
private InputDevice device;
|
|
private List<InputDevice> devices = new List<InputDevice>();
|
|
|
|
void Start()
|
|
{
|
|
ray = GetComponent<XRInteractorLineVisual>();
|
|
ray.enabled = false;
|
|
|
|
//reticle = GameObject.FindWithTag("Reticle");
|
|
//reticle.SetActive(false);
|
|
}
|
|
|
|
void GetDevice()
|
|
{
|
|
InputDevices.GetDevicesAtXRNode(xrNode, devices);
|
|
device = devices.FirstOrDefault();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (!device.isValid)
|
|
{
|
|
GetDevice();
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!device.isValid)
|
|
{
|
|
GetDevice();
|
|
}
|
|
|
|
bool trigger = false;
|
|
if (device.TryGetFeatureValue(CommonUsages.triggerButton, out trigger) && trigger)
|
|
{
|
|
ray.enabled = true;
|
|
}
|
|
|
|
else
|
|
{
|
|
ray.enabled = false;
|
|
/*
|
|
reticle = GameObject.FindWithTag("Reticle");
|
|
if (reticle != null)
|
|
{
|
|
reticle.SetActive(false);
|
|
}
|
|
*/
|
|
}
|
|
|
|
}
|
|
|
|
}
|