version 2.5.0

This commit is contained in:
Sean Lu
2024-12-06 15:44:37 +08:00
parent dfdcd0fd7f
commit 2bfa2ad4c7
966 changed files with 238216 additions and 77239 deletions

View File

@@ -4,6 +4,7 @@ using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR;
using VIVE.OpenXR;
using VIVE.OpenXR.DisplayRefreshRate;
namespace UnityEngine.XR.OpenXR.Samples.ControllerSample
{
@@ -64,10 +65,18 @@ namespace UnityEngine.XR.OpenXR.Samples.ControllerSample
m_LastRecenteredTime = Time.time;
}*/
static private void OnDisplayRateChanged(float fromRate, float toRate)
{
Debug.Log("DisplayRefreshRate fromRate = " + fromRate);
Debug.Log("DisplayRefreshRate toRate = " + toRate);
}
public void OnDesiredSelectionChanged(int newValue)
{
desiredTrackingOriginMode = (TrackingOriginModeFlags)(newValue == 0 ? 0 : (1 << (newValue - 1)));
#if UNITY_ANDROID
ViveDisplayRefreshRateChanged.Listen(OnDisplayRateChanged);
if (desiredTrackingOriginMode == TrackingOriginModeFlags.Device)
{
float value;
@@ -103,6 +112,7 @@ namespace UnityEngine.XR.OpenXR.Samples.ControllerSample
}
}
#endif
}
private void TrackingOriginUpdated(TrackingOriginModeFlags mode)

View File

@@ -35,20 +35,8 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
public bool UseInputAction { get { return m_UseInputAction; } set { m_UseInputAction = value; } }
[SerializeField]
private InputActionReference m_IsTracked = null;
public InputActionReference IsTracked { get { return m_IsTracked; } set { m_IsTracked = value; } }
[SerializeField]
private InputActionReference m_TrackingState = null;
public InputActionReference TrackingState { get { return m_TrackingState; } set { m_TrackingState = value; } }
[SerializeField]
private InputActionReference m_Position = null;
public InputActionReference Position { get { return m_Position; } set { m_Position = value; } }
[SerializeField]
private InputActionReference m_Rotation = null;
public InputActionReference Rotation { get { return m_Rotation; } set { m_Rotation = value; } }
private InputActionReference m_DevicePose = null;
public InputActionReference DevicePose { get { return m_DevicePose; } set { m_DevicePose = value; } }
#endif
/// <summary> VIVE Left Controller Characteristics </summary>
public const InputDeviceCharacteristics kControllerLeftCharacteristics = (
@@ -200,7 +188,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
{
m_Text.text += "isTracked: ";
{
if (Utils.GetButton(m_IsTracked, out bool value, out string msg))
if (CommonHelper.GetPoseIsTracked(m_DevicePose, out bool value, out string msg))
{
m_Text.text += value;
}
@@ -212,7 +200,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += "\n";
m_Text.text += "trackingState: ";
{
if (Utils.GetInteger(m_TrackingState, out InputTrackingState value, out string msg))
if (CommonHelper.GetPoseTrackingState(m_DevicePose, out InputTrackingState value, out string msg))
{
m_Text.text += value;
}
@@ -224,7 +212,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += "\n";
m_Text.text += "position (";
{
if (Utils.GetVector3(m_Position, out Vector3 value, out string msg))
if (CommonHelper.GetPosePosition(m_DevicePose, out Vector3 value, out string msg))
{
m_Text.text += value.x.ToString() + ", " + value.y.ToString() + ", " + value.z.ToString();
}
@@ -236,7 +224,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += ")\n";
m_Text.text += "rotation (";
{
if (Utils.GetQuaternion(m_Rotation, out Quaternion value, out string msg))
if (CommonHelper.GetPoseRotation(m_DevicePose, out Quaternion value, out string msg))
{
m_Text.text += value.x.ToString() + ", " + value.y.ToString() + ", " + value.z.ToString() + ", " + value.w.ToString();
}

View File

@@ -30,20 +30,8 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
#if ENABLE_INPUT_SYSTEM
[SerializeField]
private InputActionReference m_IsTracked = null;
public InputActionReference IsTracked { get { return m_IsTracked; } set { m_IsTracked = value; } }
[SerializeField]
private InputActionReference m_TrackingState = null;
public InputActionReference TrackingState { get { return m_TrackingState; } set { m_TrackingState = value; } }
[SerializeField]
private InputActionReference m_Position = null;
public InputActionReference Position { get { return m_Position; } set { m_Position = value; } }
[SerializeField]
private InputActionReference m_Rotation = null;
public InputActionReference Rotation { get { return m_Rotation; } set { m_Rotation = value; } }
private InputActionReference m_GripPose = null;
public InputActionReference GripPose { get { return m_GripPose; } set { m_GripPose = value; } }
[SerializeField]
private InputActionReference m_Strength = null;
@@ -72,7 +60,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
#if ENABLE_INPUT_SYSTEM
m_Text.text += "\nisTracked: ";
{
if (Utils.GetButton(m_IsTracked, out bool value, out string msg))
if (CommonHelper.GetPoseIsTracked(m_GripPose, out bool value, out string msg))
{
m_Text.text += value;
}
@@ -83,7 +71,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += "\ntrackingState: ";
{
if (Utils.GetInteger(m_TrackingState, out InputTrackingState value, out string msg))
if (CommonHelper.GetPoseTrackingState(m_GripPose, out InputTrackingState value, out string msg))
{
m_Text.text += value;
}
@@ -94,7 +82,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += "\nposition (";
{
if (Utils.GetVector3(m_Position, out Vector3 value, out string msg))
if (CommonHelper.GetPosePosition(m_GripPose, out Vector3 value, out string msg))
{
m_Text.text += value.x.ToString() + ", " + value.y.ToString() + ", " + value.z.ToString();
}
@@ -105,7 +93,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += ")\nrotation (";
{
if (Utils.GetQuaternion(m_Rotation, out Quaternion value, out string msg))
if (CommonHelper.GetPoseRotation(m_GripPose, out Quaternion value, out string msg))
{
m_Text.text += value.x.ToString() + ", " + value.y.ToString() + ", " + value.z.ToString() + ", " + value.w.ToString();
}
@@ -116,7 +104,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += ")\nstrength: ";
{
if (Utils.GetAnalog(m_Strength, out float value, out string msg))
if (CommonHelper.GetAnalog(m_Strength, out float value, out string msg))
{
m_Text.text += value.ToString();
}
@@ -131,7 +119,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
#if ENABLE_INPUT_SYSTEM
m_Text.text += "\nisTracked: ";
{
if (Utils.GetPoseIsTracked(m_AimPose, out bool value, out string msg))
if (CommonHelper.GetPoseIsTracked(m_AimPose, out bool value, out string msg))
{
m_Text.text += value;
}
@@ -142,7 +130,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += "\ntrackingState: ";
{
if (Utils.GetPoseTrackingState(m_AimPose, out InputTrackingState value, out string msg))
if (CommonHelper.GetPoseTrackingState(m_AimPose, out InputTrackingState value, out string msg))
{
m_Text.text += value;
}
@@ -153,7 +141,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += "\nposition (";
{
if (Utils.GetPosePosition(m_AimPose, out Vector3 value, out string msg))
if (CommonHelper.GetPosePosition(m_AimPose, out Vector3 value, out string msg))
{
m_Text.text += value.x.ToString() + ", " + value.y.ToString() + ", " + value.z.ToString();
}
@@ -164,7 +152,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += ")\nrotation (";
{
if (Utils.GetPoseRotation(m_AimPose, out Quaternion value, out string msg))
if (CommonHelper.GetPoseRotation(m_AimPose, out Quaternion value, out string msg))
{
m_Text.text += value.x.ToString() + ", " + value.y.ToString() + ", " + value.z.ToString() + ", " + value.w.ToString();
}
@@ -176,7 +164,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += ")\n";
m_Text.text += "select: ";
{
if (Utils.GetAnalog(m_SelectValue, out float value, out string msg))
if (CommonHelper.GetAnalog(m_SelectValue, out float value, out string msg))
{
m_Text.text += value;
}

View File

@@ -21,11 +21,11 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
if (m_DevicePose == null) { return; }
string msg = "";
if (Utils.GetPosePosition(m_DevicePose, out Vector3 pos, out msg))
if (CommonHelper.GetPosePosition(m_DevicePose, out Vector3 pos, out msg))
{
transform.localPosition = pos;
}
if (Utils.GetPoseRotation(m_DevicePose, out Quaternion rot, out msg))
if (CommonHelper.GetPoseRotation(m_DevicePose, out Quaternion rot, out msg))
{
transform.localRotation = rot;
}

View File

@@ -172,16 +172,20 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
if (getButton(m_Menu))
DEBUG("Update() " + m_Menu.name + " is pressed.");
if (tracked)
#if !UNITY_XR_OPENXR_1_6_0
if (tracked) // The isTracked value of Pose will always be flase in OpenXR 1.6.0
#endif
{
transform.localPosition = position;
transform.localRotation = rotation;
}
#if !UNITY_XR_OPENXR_1_6_0
else
{
if (printIntervalLog)
DEBUG("Update() Tracker is not tracked.");
}
#endif
}
}
}

View File

@@ -59,20 +59,20 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text = "Left Tracker ";
{ // Tracked
if (Utils.GetButton(m_TrackedL, out bool value, out string msg))
if (CommonHelper.GetButton(m_TrackedL, out bool value, out string msg))
{
m_Text.text += "tracked: " + value + ", ";
}
}
{ // trackingState
if (Utils.GetInteger(m_TrackingStateL, out InputTrackingState value, out string msg))
if (CommonHelper.GetInteger(m_TrackingStateL, out InputTrackingState value, out string msg))
{
m_Text.text += "state: " + value + ", ";
}
}
{ // Left X
if (Utils.GetButton(m_LeftX, out bool value, out string msg))
if (CommonHelper.GetButton(m_LeftX, out bool value, out string msg))
{
if (value)
{
@@ -82,7 +82,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
}
{ // Left Menu
if (Utils.GetButton(m_LeftMenu, out bool value, out string msg))
if (CommonHelper.GetButton(m_LeftMenu, out bool value, out string msg))
{
if (value)
{
@@ -96,20 +96,20 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += "\nRight Tracker ";
{ // Tracked
if (Utils.GetButton(m_TrackedR, out bool value, out string msg))
if (CommonHelper.GetButton(m_TrackedR, out bool value, out string msg))
{
m_Text.text += "tracked: " + value + ", ";
}
}
{ // trackingState
if (Utils.GetInteger(m_TrackingStateR, out InputTrackingState value, out string msg))
if (CommonHelper.GetInteger(m_TrackingStateR, out InputTrackingState value, out string msg))
{
m_Text.text += "state: " + value + ", ";
}
}
{ // Right A
if (Utils.GetButton(m_RightA, out bool value, out string msg))
if (CommonHelper.GetButton(m_RightA, out bool value, out string msg))
{
if (value)
{

View File

@@ -64,10 +64,6 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
private InputActionReference m_TrackpadPress = null;
public InputActionReference TrackpadPress { get { return m_TrackpadPress; } set { m_TrackpadPress = value; } }
[SerializeField]
private InputActionReference m_TrackpadTouch = null;
public InputActionReference TrackpadTouch { get { return m_TrackpadTouch; } set { m_TrackpadTouch = value; } }
private Text m_Text = null;
private void Start()
{
@@ -82,7 +78,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += " isTracked: ";
{
if (Utils.GetButton(m_IsTracked, out bool value, out string msg))
if (CommonHelper.GetButton(m_IsTracked, out bool value, out string msg))
{
m_Text.text += value;
}
@@ -94,7 +90,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += "\n";
m_Text.text += "trackingState: ";
{
if (Utils.GetInteger(m_TrackingState, out InputTrackingState value, out string msg))
if (CommonHelper.GetInteger(m_TrackingState, out InputTrackingState value, out string msg))
{
m_Text.text += value;
}
@@ -106,7 +102,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += "\n";
m_Text.text += "position (";
{
if (Utils.GetVector3(m_Position, out Vector3 value, out string msg))
if (CommonHelper.GetVector3(m_Position, out Vector3 value, out string msg))
{
m_Text.text += value.x.ToString() + ", " + value.y.ToString() + ", " + value.z.ToString();
}
@@ -118,7 +114,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += ")\n";
m_Text.text += "rotation (";
{
if (Utils.GetQuaternion(m_Rotation, out Quaternion value, out string msg))
if (CommonHelper.GetQuaternion(m_Rotation, out Quaternion value, out string msg))
{
m_Text.text += value.x.ToString() + ", " + value.y.ToString() + ", " + value.z.ToString() + ", " + value.w.ToString();
}
@@ -130,7 +126,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
m_Text.text += ")";
m_Text.text += "\nmenu: ";
{
if (Utils.GetButton(m_Menu, out bool value, out string msg))
if (CommonHelper.GetButton(m_Menu, out bool value, out string msg))
{
m_Text.text += value;
}
@@ -141,7 +137,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += "\ngrip: ";
{
if (Utils.GetButton(m_GripPress, out bool value, out string msg))
if (CommonHelper.GetButton(m_GripPress, out bool value, out string msg))
{
m_Text.text += value;
}
@@ -152,11 +148,11 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += "\ntrigger press: ";
{
if (Utils.GetButton(m_TriggerPress, out bool value, out string msg))
if (CommonHelper.GetButton(m_TriggerPress, out bool value, out string msg))
{
m_Text.text += value;
if (Utils.PerformHaptic(m_TriggerPress, out msg))
if (CommonHelper.PerformHaptic(m_TriggerPress, out msg))
{
m_Text.text += ", Vibrate";
}
@@ -172,18 +168,7 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
}
m_Text.text += "\ntrackpad press: ";
{
if (Utils.GetButton(m_TrackpadPress, out bool value, out string msg))
{
m_Text.text += value;
}
else
{
m_Text.text += msg;
}
}
m_Text.text += "\ntrackpad touch: ";
{
if (Utils.GetButton(m_TrackpadTouch, out bool value, out string msg))
if (CommonHelper.GetButton(m_TrackpadPress, out bool value, out string msg))
{
m_Text.text += value;
}

View File

@@ -0,0 +1,56 @@
// Copyright HTC Corporation All Rights Reserved.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.OpenXR;
/*#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif*/
using VIVE.OpenXR.FrameSynchronization;
namespace VIVE.OpenXR.Samples.OpenXRInput
{
[RequireComponent(typeof(Text))]
public class UserPresence : MonoBehaviour
{
private Text m_Text = null;
private void Awake()
{
m_Text = GetComponent<Text>();
}
private void OnEnable()
{
GetFrameSynchronizationMode();
}
private void Update()
{
if (m_Text == null) { return; }
m_Text.text = "User is " + (IsUserPresent() ? "Present" : "Away") + ", " + m_FrameSynchronizationMode;
//Debug.LogFormat("VIVE.OpenXR.Samples.OpenXRInput.UserPresence Update() {0}", m_Text.text);
}
public bool IsUserPresent()
{
/*#if UNITY_ANDROID && ENABLE_INPUT_SYSTEM
if (ProximitySensor.current != null)
{
if (!ProximitySensor.current.IsActuated())
InputSystem.EnableDevice(ProximitySensor.current);
return ProximitySensor.current.distance.ReadValue() < 1; // near p-sensor < 1cm
}
#endif*/
return XR_EXT_user_presence.Interop.IsUserPresent();
}
private string m_FrameSynchronizationMode = "No FS";
private void GetFrameSynchronizationMode()
{
ViveFrameSynchronization feature = OpenXRSettings.Instance.GetFeature<ViveFrameSynchronization>();
m_FrameSynchronizationMode = feature ? feature.GetSynchronizationMode().ToString() : "No FS";
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 06fce22bc702c664fb91ec6da2adb7a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -10,6 +10,7 @@ using UnityEngine.InputSystem;
namespace VIVE.OpenXR.Samples.OpenXRInput
{
[Obsolete("This class is deprecated. Please use VIVE.OpenXR.Samples.CommonHelper instead.")]
public static class Utils
{
public enum DeviceTypes : UInt32
@@ -219,7 +220,6 @@ namespace VIVE.OpenXR.Samples.OpenXRInput
if (actionReference.action.activeControl.valueType == typeof(Quaternion))
value = actionReference.action.ReadValue<Quaternion>();
Vector3 direction = value * Vector3.forward;
return true;
}