Skip to content

Commit 21f5a98

Browse files
StayTalmRene Damm
authored andcommitted
CHANGE: Make XR device descriptor structs public (#981).
1 parent 0cded04 commit 21f5a98

File tree

3 files changed

+69
-14
lines changed

3 files changed

+69
-14
lines changed

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/TrackedPoseDriver.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void BindPosition()
9292
{
9393
if (!m_PositionBound && m_PositionAction != null)
9494
{
95+
m_PositionAction.Rename($"{gameObject.name} - TPD - Position");
9596
m_PositionAction.performed += OnPositionUpdate;
9697
m_PositionBound = true;
9798
m_PositionAction.Enable();
@@ -102,6 +103,7 @@ void BindRotation()
102103
{
103104
if (!m_RotationBound && m_RotationAction != null)
104105
{
106+
m_RotationAction.Rename($"{gameObject.name} - TPD - Rotation");
105107
m_RotationAction.performed += OnRotationUpdate;
106108
m_RotationBound = true;
107109
m_RotationAction.Enable();

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/XRLayoutBuilder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ private static uint GetSizeOfFeature(XRFeatureDescriptor featureDescriptor)
4343
return 0;
4444
}
4545

46-
private static string SanitizeName(string originalName)
46+
private static string SanitizeString(string original, bool allowPaths = false)
4747
{
48-
var stringLength = originalName.Length;
48+
var stringLength = original.Length;
4949
var sanitizedName = new StringBuilder(stringLength);
5050
for (var i = 0; i < stringLength; i++)
5151
{
52-
var letter = originalName[i];
53-
if (char.IsUpper(letter) || char.IsLower(letter) || char.IsDigit(letter))
52+
var letter = original[i];
53+
if (char.IsUpper(letter) || char.IsLower(letter) || char.IsDigit(letter) || (allowPaths && (letter == '/')))
5454
{
5555
sanitizedName.Append(letter);
5656
}
@@ -109,12 +109,12 @@ internal static string OnFindLayoutForDevice(ref InputDeviceDescription descript
109109
string layoutName;
110110
if (string.IsNullOrEmpty(description.manufacturer))
111111
{
112-
layoutName = $"{SanitizeName(description.interfaceName)}::{SanitizeName(description.product)}";
112+
layoutName = $"{SanitizeString(description.interfaceName)}::{SanitizeString(description.product)}";
113113
}
114114
else
115115
{
116116
layoutName =
117-
$"{SanitizeName(description.interfaceName)}::{SanitizeName(description.manufacturer)}::{SanitizeName(description.product)}";
117+
$"{SanitizeString(description.interfaceName)}::{SanitizeString(description.manufacturer)}::{SanitizeString(description.product)}";
118118
}
119119

120120
var layout = new XRLayoutBuilder { descriptor = deviceDescriptor, parentLayout = matchedLayout, interfaceName = description.interfaceName };
@@ -174,7 +174,7 @@ private InputControlLayout Build()
174174
}
175175

176176
var featureName = feature.name;
177-
featureName = SanitizeName(featureName);
177+
featureName = SanitizeString(featureName, true);
178178
if (inheritedLayout != null)
179179
featureName = ConvertPotentialAliasToName(inheritedLayout, featureName);
180180

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/XRSupport.cs

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public static class XRUtilities
3030
}
3131

3232
// Sync to UnityXRInputFeatureType in IUnityXRInput.h
33-
enum FeatureType
33+
/// <summary>
34+
/// The type of data a <see cref="XRFeatureDescriptor>"/> exposes.
35+
/// </summary>
36+
public enum FeatureType
3437
{
3538
Custom = 0,
3639
Binary,
@@ -44,45 +47,95 @@ enum FeatureType
4447
Eyes
4548
}
4649

47-
// These structures are not explicitly assigned, but they are filled in via JSON serialization coming from matching structs in native.
50+
/// <summary>
51+
/// Contextual strings that identify the contextual, cross-platform use that a feature represents. <see cref="UnityEngine.XR.CommonUsages"/> for a list of unity's built-in shared usages.
52+
/// </summary>
4853
#pragma warning disable 0649
4954
[Serializable]
50-
struct UsageHint
55+
public struct UsageHint
5156
{
5257
public string content;
5358
}
5459

5560
//Sync to XRInputFeatureDefinition in XRInputDeviceDefinition.h
61+
/// <summary>
62+
/// Describes an individual input on a device, such as a trackpad, or button, or trigger.
63+
/// </summary>
5664
[Serializable]
57-
struct XRFeatureDescriptor
65+
public struct XRFeatureDescriptor
5866
{
67+
/// <summary>
68+
/// The name of the feature.
69+
/// </summary>
5970
public string name;
71+
/// <summary>
72+
/// The uses that this feature should represent, such as trigger, or grip, or touchpad.
73+
/// </summary>
6074
public List<UsageHint> usageHints;
75+
/// <summary>
76+
/// The type of data this feature exposes.
77+
/// </summary>
6178
public FeatureType featureType;
79+
/// <summary>
80+
/// The overall size of the feature. This is only filled in when the <see cref="XRFeatureDescriptor.featureType"/> is <see cref="FeatureType.Custom"/>.
81+
/// </summary>
6282
public uint customSize;
6383
}
6484

6585
//Sync to XRInputDeviceDefinition in XRInputDeviceDefinition.h
86+
/// <summary>
87+
/// Describes an input device: what it can do and how it should be used. These are reported during device connection, and help identify devices and map input data to the right controls.
88+
/// </summary>
6689
[Serializable]
67-
class XRDeviceDescriptor
90+
public class XRDeviceDescriptor
6891
{
92+
/// <summary>
93+
/// The name of the device.
94+
/// </summary>
6995
public string deviceName;
96+
/// <summary>
97+
/// The manufacturer of the device.
98+
/// </summary>
7099
public string manufacturer;
100+
/// <summary>
101+
/// The serial number of the device. An empty string if no serial number is available.
102+
/// </summary>
71103
public string serialNumber;
72104
#if UNITY_2019_3_OR_NEWER
105+
/// <summary>
106+
/// The capabilities of the device, used to help filter and identify devices that server a certain purpose (e.g. controller, or headset, or hardware tracker).
107+
/// </summary>
73108
public InputDeviceCharacteristics characteristics;
74109
#else //UNITY_2019_3_OR_NEWER
110+
/// <summary>
111+
/// The role of the device, used to help filter and identify devices that server a certain purpose (e.g. controller, or headset, or hardware tracker).
112+
/// </summary>
75113
public InputDeviceRole deviceRole;
76114
#endif //UNITY_2019_3_OR_NEWER
115+
/// <summary>
116+
/// The underlying deviceId, this can be used with <see cref="UnityEngine.XR.InputDevices"/> to create a device.
117+
/// </summary>
77118
public int deviceId;
119+
/// <summary>
120+
/// A list of all input features. <seealso cref="XRFeatureDescriptor"/>
121+
/// </summary>
78122
public List<XRFeatureDescriptor> inputFeatures;
79123

80-
internal string ToJson()
124+
/// <summary>
125+
/// Converts this structure to a JSON string.
126+
/// </summary>
127+
/// <returns></returns>
128+
public string ToJson()
81129
{
82130
return JsonUtility.ToJson(this);
83131
}
84132

85-
internal static XRDeviceDescriptor FromJson(string json)
133+
/// <summary>
134+
/// Converts a json string to a new <see cref="XRDeviceDescriptor"/>.
135+
/// </summary>
136+
/// <param name="json">The JSON string containing <see cref="XRDeviceDescriptor"/> data.</param>
137+
/// <returns>A new <see cref="XRDeviceDescriptor"/></returns>
138+
public static XRDeviceDescriptor FromJson(string json)
86139
{
87140
return JsonUtility.FromJson<XRDeviceDescriptor>(json);
88141
}

0 commit comments

Comments
 (0)