Fixed player location calculation via camera trigger collider
This commit is contained in:
61
Assets/Oculus Hands Physics/Scripts/HandPresence.cs
Normal file
61
Assets/Oculus Hands Physics/Scripts/HandPresence.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
|
||||
public class HandPresence : MonoBehaviour
|
||||
{
|
||||
public InputDeviceCharacteristics controllerCharacteristics;
|
||||
private InputDevice targetDevice;
|
||||
public Animator handAnimator;
|
||||
|
||||
void Start()
|
||||
{
|
||||
TryInitialize();
|
||||
}
|
||||
|
||||
void TryInitialize()
|
||||
{
|
||||
List<InputDevice> devices = new List<InputDevice>();
|
||||
|
||||
InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);
|
||||
if (devices.Count > 0)
|
||||
{
|
||||
targetDevice = devices[0];
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateHandAnimation()
|
||||
{
|
||||
if(targetDevice.TryGetFeatureValue(CommonUsages.trigger, out float triggerValue))
|
||||
{
|
||||
handAnimator.SetFloat("Trigger", triggerValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
handAnimator.SetFloat("Trigger", 0);
|
||||
}
|
||||
|
||||
if (targetDevice.TryGetFeatureValue(CommonUsages.grip, out float gripValue))
|
||||
{
|
||||
handAnimator.SetFloat("Grip", gripValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
handAnimator.SetFloat("Grip", 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(!targetDevice.isValid)
|
||||
{
|
||||
TryInitialize();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateHandAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Oculus Hands Physics/Scripts/HandPresence.cs.meta
Normal file
11
Assets/Oculus Hands Physics/Scripts/HandPresence.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99b4a737903b82a43bb95804a2149147
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user