deltavr multiplayer 2.0
This commit is contained in:
80
Assets/_PROJECT/Scripts/UnityXR/HandPresence.cs
Normal file
80
Assets/_PROJECT/Scripts/UnityXR/HandPresence.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
|
||||
namespace UnityXR
|
||||
{
|
||||
public class HandPresence : MonoBehaviour
|
||||
{
|
||||
public bool showController;
|
||||
public InputDeviceCharacteristics controllerCharacteristics;
|
||||
public List<GameObject> controllerPrefabs;
|
||||
public GameObject handModelPrefab;
|
||||
|
||||
private InputDevice _targetDevice;
|
||||
private GameObject _spawnedController;
|
||||
private GameObject _spawnedHandModel;
|
||||
private Animator _handAnimator;
|
||||
|
||||
private static readonly int Trigger = Animator.StringToHash("Trigger");
|
||||
private static readonly int Grip = Animator.StringToHash("Grip");
|
||||
|
||||
private void TryInitialize()
|
||||
{
|
||||
var devices = new List<InputDevice>();
|
||||
InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);
|
||||
if (devices.Count <= 0) return;
|
||||
|
||||
_targetDevice = devices[0];
|
||||
GameObject prefab = controllerPrefabs.Find(controller => controller.name == _targetDevice.name);
|
||||
_spawnedController = Instantiate(prefab ? prefab : controllerPrefabs[0], transform);
|
||||
|
||||
_spawnedHandModel = Instantiate(handModelPrefab, transform);
|
||||
_handAnimator = _spawnedHandModel.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private 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
|
||||
{
|
||||
if (showController)
|
||||
{
|
||||
_spawnedHandModel.SetActive(false);
|
||||
_spawnedController.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_spawnedHandModel.SetActive(true);
|
||||
_spawnedController.SetActive(false);
|
||||
UpdateHandAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_PROJECT/Scripts/UnityXR/HandPresence.cs.meta
Normal file
11
Assets/_PROJECT/Scripts/UnityXR/HandPresence.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df6b462fef11acb4fb7d56a91c73b4b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
namespace UnityXR
|
||||
{
|
||||
public class WorldSpaceUpTeleportWorldArea : TeleportationArea
|
||||
{
|
||||
// Override the teleport request to use the world rotation and not our gameObject's transform
|
||||
protected override bool GenerateTeleportRequest(IXRInteractor interactor, RaycastHit raycastHit, ref TeleportRequest teleportRequest)
|
||||
{
|
||||
teleportRequest.destinationPosition = raycastHit.point;
|
||||
teleportRequest.matchOrientation = MatchOrientation.WorldSpaceUp; // use the area transform for data.
|
||||
teleportRequest.destinationRotation = Quaternion.identity;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bc374ab13b4e224384b965358d295cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Assets/_PROJECT/Scripts/UnityXR/XRGrabVelocityTracked.cs
Normal file
26
Assets/_PROJECT/Scripts/UnityXR/XRGrabVelocityTracked.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class XRGrabVelocityTracked : XRGrabInteractable
|
||||
{
|
||||
protected override void OnSelectEntered(SelectEnterEventArgs args)
|
||||
{
|
||||
SetParentToXRRig();
|
||||
base.OnSelectEntered(args);
|
||||
}
|
||||
|
||||
protected override void OnSelectExited(SelectExitEventArgs args)
|
||||
{
|
||||
SetParentToWorld();
|
||||
base.OnSelectExited(args);
|
||||
}
|
||||
|
||||
public void SetParentToXRRig()
|
||||
{
|
||||
transform.SetParent(interactorsSelecting[0].transform);
|
||||
}
|
||||
|
||||
public void SetParentToWorld()
|
||||
{
|
||||
transform.SetParent(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c96c5d5e9ecc35d4b8732d567d0c8458
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user