71 lines
1.5 KiB
C#
71 lines
1.5 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 Hand_Ray_OnOff : MonoBehaviour
|
|
{
|
|
private Player player;
|
|
public GameObject ray;
|
|
|
|
[SerializeField]
|
|
public XRNode xrNode = XRNode.RightHand;
|
|
private InputDevice device;
|
|
private List<InputDevice> devices = new List<InputDevice>();
|
|
|
|
void Start()
|
|
{
|
|
player = FindObjectOfType<Player>();
|
|
ray.SetActive(false);
|
|
}
|
|
|
|
void GetDevice()
|
|
{
|
|
InputDevices.GetDevicesAtXRNode(xrNode, devices);
|
|
device = devices.FirstOrDefault();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (!device.isValid)
|
|
{
|
|
GetDevice();
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!device.isValid)
|
|
{
|
|
GetDevice();
|
|
}
|
|
|
|
if (!player.isDummy)
|
|
{
|
|
bool trigger = false;
|
|
if (device.TryGetFeatureValue(CommonUsages.triggerButton, out trigger) && trigger)
|
|
{
|
|
ray.SetActive(true);
|
|
player.Hand_Ray_Send("On");
|
|
}
|
|
|
|
else
|
|
{
|
|
ray.SetActive(false);
|
|
player.Hand_Ray_Send("Off");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DummyOnOff(bool o)
|
|
{
|
|
ray.SetActive(o);
|
|
}
|
|
}
|