75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.XR;
|
|
|
|
public class HandPresence : MonoBehaviour
|
|
{
|
|
public GameObject handModelPrefab;
|
|
|
|
private GameObject spawnedHandModel;
|
|
|
|
|
|
private InputDevice targetDevice;
|
|
private Animator handAnimator;
|
|
|
|
void Start()
|
|
{
|
|
List<InputDevice> devices = new List<InputDevice>();
|
|
InputDeviceCharacteristics rightControllerCharacteristice = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
|
|
InputDevices.GetDevicesWithCharacteristics(rightControllerCharacteristice, devices);
|
|
|
|
foreach (var item in devices)
|
|
{
|
|
print(item.name + item.characteristics);
|
|
|
|
}
|
|
|
|
if (devices.Count > 0)
|
|
{
|
|
targetDevice = devices[0];
|
|
|
|
spawnedHandModel = Instantiate(handModelPrefab, transform);
|
|
handAnimator = spawnedHandModel.GetComponent<Animator>();
|
|
}
|
|
}
|
|
|
|
void UpdateHandAnimation()
|
|
{
|
|
if(targetDevice.TryGetFeatureValue(CommonUsages.trigger, out float triggerVaule))
|
|
{
|
|
print("Trigger");
|
|
handAnimator.SetFloat("Trigger", triggerVaule);
|
|
}
|
|
else
|
|
{
|
|
handAnimator.SetFloat("Trigger", 0);
|
|
}
|
|
|
|
if (targetDevice.TryGetFeatureValue(CommonUsages.grip, out float gripVaule))
|
|
{
|
|
handAnimator.SetFloat("Grip", gripVaule);
|
|
}
|
|
else
|
|
{
|
|
handAnimator.SetFloat("Grip", 0);
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
//if (targetDevice.TryGetFeatureValue(CommonUsages.primaryButton, out bool primaryButtonValue) && primaryButtonValue)
|
|
// Debug.Log("Pressing Primary Button");
|
|
|
|
//if (targetDevice.TryGetFeatureValue(CommonUsages.trigger, out float triggerValue) && triggerValue > 0.1f)
|
|
// Debug.Log("triggerValue" + triggerValue);
|
|
|
|
//if (targetDevice.TryGetFeatureValue(CommonUsages.primary2DAxis, out Vector2 primary2DAxisValue) && primary2DAxisValue != Vector2.zero)
|
|
// Debug.Log("primary2DAxisValue" + primary2DAxisValue);
|
|
|
|
UpdateHandAnimation();
|
|
}
|
|
|
|
}
|
|
|