| |
| #if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION |
| using System; |
| using System.Collections.Generic; |
| using UnityEngine.InputSystem.Layouts; |
| using UnityEngine.InputSystem.Controls; |
| using UnityEngine.XR; |
|
|
| namespace UnityEngine.InputSystem.XR |
| { |
| |
| |
| |
| public static class XRUtilities |
| { |
| |
| |
| |
| public const string InterfaceMatchAnyVersion = "^(XRInput)"; |
|
|
| |
| |
| |
| public const string InterfaceV1 = "XRInput"; |
|
|
| |
| |
| |
| public const string InterfaceCurrent = "XRInputV1"; |
| } |
|
|
| |
| |
| |
| |
| public enum FeatureType |
| { |
| Custom = 0, |
| Binary, |
| DiscreteStates, |
| Axis1D, |
| Axis2D, |
| Axis3D, |
| Rotation, |
| Hand, |
| Bone, |
| Eyes |
| } |
|
|
| |
| |
| |
| #pragma warning disable 0649 |
| [Serializable] |
| public struct UsageHint |
| { |
| public string content; |
| } |
|
|
| |
| |
| |
| |
| [Serializable] |
| public struct XRFeatureDescriptor |
| { |
| |
| |
| |
| public string name; |
| |
| |
| |
| public List<UsageHint> usageHints; |
| |
| |
| |
| public FeatureType featureType; |
| |
| |
| |
| public uint customSize; |
| } |
|
|
| |
| |
| |
| |
| [Serializable] |
| public class XRDeviceDescriptor |
| { |
| |
| |
| |
| public string deviceName; |
| |
| |
| |
| public string manufacturer; |
| |
| |
| |
| public string serialNumber; |
| |
| |
| |
| public InputDeviceCharacteristics characteristics; |
| |
| |
| |
| public int deviceId; |
| |
| |
| |
| public List<XRFeatureDescriptor> inputFeatures; |
|
|
| |
| |
| |
| |
| public string ToJson() |
| { |
| return JsonUtility.ToJson(this); |
| } |
|
|
| |
| |
| |
| |
| |
| public static XRDeviceDescriptor FromJson(string json) |
| { |
| return JsonUtility.FromJson<XRDeviceDescriptor>(json); |
| } |
| } |
|
|
| |
| |
| |
| public struct Bone |
| { |
| |
| |
| |
| public uint m_ParentBoneIndex; |
|
|
| |
| |
| |
| public Vector3 m_Position; |
|
|
| |
| |
| |
| public Quaternion m_Rotation; |
|
|
| |
| |
| |
| public uint parentBoneIndex |
| { |
| get => m_ParentBoneIndex; |
| set => m_ParentBoneIndex = value; |
| } |
|
|
| |
| |
| |
| public Vector3 position |
| { |
| get => m_Position; |
| set => m_Position = value; |
| } |
|
|
| |
| |
| |
| public Quaternion rotation |
| { |
| get => m_Rotation; |
| set => m_Rotation = value; |
| } |
| } |
|
|
| |
| |
| |
| public struct Eyes |
| { |
| |
| |
| |
| public Vector3 m_LeftEyePosition; |
| |
| |
| |
| public Quaternion m_LeftEyeRotation; |
| |
| |
| |
| public Vector3 m_RightEyePosition; |
| |
| |
| |
| public Quaternion m_RightEyeRotation; |
| |
| |
| |
| public Vector3 m_FixationPoint; |
| |
| |
| |
| public float m_LeftEyeOpenAmount; |
| |
| |
| |
| public float m_RightEyeOpenAmount; |
|
|
| |
| |
| |
| public Vector3 leftEyePosition |
| { |
| get => m_LeftEyePosition; |
| set => m_LeftEyePosition = value; |
| } |
|
|
| |
| |
| |
| public Quaternion leftEyeRotation |
| { |
| get => m_LeftEyeRotation; |
| set => m_LeftEyeRotation = value; |
| } |
|
|
| |
| |
| |
| public Vector3 rightEyePosition |
| { |
| get => m_RightEyePosition; |
| set => m_RightEyePosition = value; |
| } |
|
|
| |
| |
| |
| public Quaternion rightEyeRotation |
| { |
| get => m_RightEyeRotation; |
| set => m_RightEyeRotation = value; |
| } |
|
|
| |
| |
| |
| public Vector3 fixationPoint |
| { |
| get => m_FixationPoint; |
| set => m_FixationPoint = value; |
| } |
|
|
| |
| |
| |
| public float leftEyeOpenAmount |
| { |
| get => m_LeftEyeOpenAmount; |
| set => m_LeftEyeOpenAmount = value; |
| } |
|
|
| |
| |
| |
| public float rightEyeOpenAmount |
| { |
| get => m_RightEyeOpenAmount; |
| set => m_RightEyeOpenAmount = value; |
| } |
| } |
|
|
| public class BoneControl : InputControl<Bone> |
| { |
| [InputControl(offset = 0, displayName = "parentBoneIndex")] |
| public IntegerControl parentBoneIndex { get; private set; } |
| [InputControl(offset = 4, displayName = "Position")] |
| public Vector3Control position { get; private set; } |
| [InputControl(offset = 16, displayName = "Rotation")] |
| public QuaternionControl rotation { get; private set; } |
|
|
| protected override void FinishSetup() |
| { |
| parentBoneIndex = GetChildControl<IntegerControl>("parentBoneIndex"); |
| position = GetChildControl<Vector3Control>("position"); |
| rotation = GetChildControl<QuaternionControl>("rotation"); |
|
|
| base.FinishSetup(); |
| } |
|
|
| public override unsafe Bone ReadUnprocessedValueFromState(void* statePtr) |
| { |
| return new Bone() |
| { |
| parentBoneIndex = (uint)parentBoneIndex.ReadUnprocessedValueFromStateWithCaching(statePtr), |
| position = position.ReadUnprocessedValueFromStateWithCaching(statePtr), |
| rotation = rotation.ReadUnprocessedValueFromStateWithCaching(statePtr) |
| }; |
| } |
|
|
| public override unsafe void WriteValueIntoState(Bone value, void* statePtr) |
| { |
| parentBoneIndex.WriteValueIntoState((int)value.parentBoneIndex, statePtr); |
| position.WriteValueIntoState(value.position, statePtr); |
| rotation.WriteValueIntoState(value.rotation, statePtr); |
| } |
| } |
|
|
| public class EyesControl : InputControl<Eyes> |
| { |
| [InputControl(offset = 0, displayName = "LeftEyePosition")] |
| public Vector3Control leftEyePosition { get; private set; } |
| [InputControl(offset = 12, displayName = "LeftEyeRotation")] |
| public QuaternionControl leftEyeRotation { get; private set; } |
| [InputControl(offset = 28, displayName = "RightEyePosition")] |
| public Vector3Control rightEyePosition { get; private set; } |
| [InputControl(offset = 40, displayName = "RightEyeRotation")] |
| public QuaternionControl rightEyeRotation { get; private set; } |
| [InputControl(offset = 56, displayName = "FixationPoint")] |
| public Vector3Control fixationPoint { get; private set; } |
| [InputControl(offset = 68, displayName = "LeftEyeOpenAmount")] |
| public AxisControl leftEyeOpenAmount { get; private set; } |
| [InputControl(offset = 72, displayName = "RightEyeOpenAmount")] |
| public AxisControl rightEyeOpenAmount { get; private set; } |
|
|
| protected override void FinishSetup() |
| { |
| leftEyePosition = GetChildControl<Vector3Control>("leftEyePosition"); |
| leftEyeRotation = GetChildControl<QuaternionControl>("leftEyeRotation"); |
| rightEyePosition = GetChildControl<Vector3Control>("rightEyePosition"); |
| rightEyeRotation = GetChildControl<QuaternionControl>("rightEyeRotation"); |
| fixationPoint = GetChildControl<Vector3Control>("fixationPoint"); |
| leftEyeOpenAmount = GetChildControl<AxisControl>("leftEyeOpenAmount"); |
| rightEyeOpenAmount = GetChildControl<AxisControl>("rightEyeOpenAmount"); |
|
|
| base.FinishSetup(); |
| } |
|
|
| public override unsafe Eyes ReadUnprocessedValueFromState(void* statePtr) |
| { |
| return new Eyes() |
| { |
| leftEyePosition = leftEyePosition.ReadUnprocessedValueFromStateWithCaching(statePtr), |
| leftEyeRotation = leftEyeRotation.ReadUnprocessedValueFromStateWithCaching(statePtr), |
| rightEyePosition = rightEyePosition.ReadUnprocessedValueFromStateWithCaching(statePtr), |
| rightEyeRotation = rightEyeRotation.ReadUnprocessedValueFromStateWithCaching(statePtr), |
| fixationPoint = fixationPoint.ReadUnprocessedValueFromStateWithCaching(statePtr), |
| leftEyeOpenAmount = leftEyeOpenAmount.ReadUnprocessedValueFromStateWithCaching(statePtr), |
| rightEyeOpenAmount = rightEyeOpenAmount.ReadUnprocessedValueFromStateWithCaching(statePtr) |
| }; |
| } |
|
|
| public override unsafe void WriteValueIntoState(Eyes value, void* statePtr) |
| { |
| leftEyePosition.WriteValueIntoState(value.leftEyePosition, statePtr); |
| leftEyeRotation.WriteValueIntoState(value.leftEyeRotation, statePtr); |
| rightEyePosition.WriteValueIntoState(value.rightEyePosition, statePtr); |
| rightEyeRotation.WriteValueIntoState(value.rightEyeRotation, statePtr); |
| fixationPoint.WriteValueIntoState(value.fixationPoint, statePtr); |
| leftEyeOpenAmount.WriteValueIntoState(value.leftEyeOpenAmount, statePtr); |
| rightEyeOpenAmount.WriteValueIntoState(value.rightEyeOpenAmount, statePtr); |
| } |
| } |
| #pragma warning restore 0649 |
|
|
| |
| |
| |
| #if UNITY_DISABLE_DEFAULT_INPUT_PLUGIN_INITIALIZATION |
| public |
| #else |
| internal |
| #endif |
| static class XRSupport |
| { |
| |
| |
| |
| public static void Initialize() |
| { |
| #if !UNITY_FORCE_INPUTSYSTEM_XR_OFF |
| InputSystem.RegisterLayout<PoseControl>("Pose"); |
| InputSystem.RegisterLayout<BoneControl>("Bone"); |
| InputSystem.RegisterLayout<EyesControl>("Eyes"); |
|
|
| InputSystem.RegisterLayout<XRHMD>(); |
| InputSystem.RegisterLayout<XRController>(); |
|
|
| InputSystem.onFindLayoutForDevice += XRLayoutBuilder.OnFindLayoutForDevice; |
|
|
| |
| #if !DISABLE_BUILTIN_INPUT_SYSTEM_WINDOWSMR |
| InputSystem.RegisterLayout<UnityEngine.XR.WindowsMR.Input.WMRHMD>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct("(Windows Mixed Reality HMD)|(Microsoft HoloLens)|(^(WindowsMR Headset))") |
| ); |
| InputSystem.RegisterLayout<UnityEngine.XR.WindowsMR.Input.WMRSpatialController>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct(@"(^(Spatial Controller))|(^(OpenVR Controller\(WindowsMR))") |
| ); |
| InputSystem.RegisterLayout<UnityEngine.XR.WindowsMR.Input.HololensHand>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct(@"(^(Hand -))") |
| ); |
| #endif |
|
|
| |
| #if !DISABLE_BUILTIN_INPUT_SYSTEM_OCULUS |
| InputSystem.RegisterLayout<Unity.XR.Oculus.Input.OculusHMD>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct("^(Oculus Rift)|^(Oculus Quest)|^(Oculus Go)")); |
| InputSystem.RegisterLayout<Unity.XR.Oculus.Input.OculusTouchController>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct(@"(^(Oculus Touch Controller))|(^(Oculus Quest Controller))")); |
| InputSystem.RegisterLayout<Unity.XR.Oculus.Input.OculusRemote>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct(@"Oculus Remote")); |
| InputSystem.RegisterLayout<Unity.XR.Oculus.Input.OculusTrackingReference>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct(@"((Tracking Reference)|(^(Oculus Rift [a-zA-Z0-9]* \(Camera)))")); |
|
|
| InputSystem.RegisterLayout<Unity.XR.Oculus.Input.OculusHMDExtended>( |
| name: "GearVR", |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct("Oculus HMD")); |
| InputSystem.RegisterLayout<Unity.XR.Oculus.Input.GearVRTrackedController>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct("^(Oculus Tracked Remote)")); |
| #endif |
|
|
| |
| #if !DISABLE_BUILTIN_INPUT_SYSTEM_GOOGLEVR |
| InputSystem.RegisterLayout<Unity.XR.GoogleVr.DaydreamHMD>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct("Daydream HMD")); |
| InputSystem.RegisterLayout<Unity.XR.GoogleVr.DaydreamController>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct("^(Daydream Controller)")); |
| #endif |
|
|
| |
| #if !DISABLE_BUILTIN_INPUT_SYSTEM_OPENVR |
| InputSystem.RegisterLayout<Unity.XR.OpenVR.OpenVRHMD>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct("^(OpenVR Headset)|^(Vive Pro)") |
| ); |
| InputSystem.RegisterLayout<Unity.XR.OpenVR.OpenVRControllerWMR>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct("^(OpenVR Controller\\(WindowsMR)") |
| ); |
| InputSystem.RegisterLayout<Unity.XR.OpenVR.ViveWand>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithManufacturer("HTC") |
| .WithProduct(@"^(OpenVR Controller\(((Vive. Controller)|(VIVE. Controller)|(Vive Controller)))") |
| ); |
| InputSystem.RegisterLayout<Unity.XR.OpenVR.OpenVROculusTouchController>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithProduct(@"^(OpenVR Controller\(Oculus)") |
| ); |
|
|
| InputSystem.RegisterLayout<Unity.XR.OpenVR.ViveTracker>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithManufacturer("HTC") |
| .WithProduct(@"^(VIVE Tracker)") |
| ); |
| InputSystem.RegisterLayout<Unity.XR.OpenVR.HandedViveTracker>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithManufacturer("HTC") |
| .WithProduct(@"^(OpenVR Controller\(VIVE Tracker)") |
| ); |
| InputSystem.RegisterLayout<Unity.XR.OpenVR.ViveLighthouse>( |
| matches: new InputDeviceMatcher() |
| .WithInterface(XRUtilities.InterfaceMatchAnyVersion) |
| .WithManufacturer("HTC") |
| .WithProduct(@"^(HTC V2-XD/XE)") |
| ); |
| #endif |
| #endif |
| } |
| } |
| } |
| #endif |
|
|