This repository has been archived on 2026-01-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Frontec/Assets/Scripts/VR/HandPresence.cs
jmaniuvc 2936c48466 Frontec
2025-02-24 12:12:52 +09:00

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();
}
}