Skip to content

Commit f2e8ea5

Browse files
authored
CHANGE: Refactor class conditional guards (#2183)
1 parent 50b0592 commit f2e8ea5

File tree

14 files changed

+122
-73
lines changed

14 files changed

+122
-73
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ however, it has to be formatted properly to pass verification tests.
4545

4646
### Changed
4747
- Changed enum value `Key.IMESelected` to obsolete which was not a real key. Please use the ButtonControl `imeSelected`.
48+
- Changed conditional guards inside Plugins/XR so that we don't unnecessarily wrap entire classes. This stops downstream packages from having to also wrap Input System objects with similar conditionals.
4849

4950
### Added
5051
- Added support of F13-F24 keys. [UUM-44328](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-44328)

Packages/com.unity.inputsystem/Documentation~/filter.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,54 @@ apiRules:
3737
- exclude:
3838
uidRegex: ^UnityEngine\.InputSystem\.InputSystem\.runInBackground$
3939
type: Member
40+
- exclude:
41+
uidRegex: ^Unity\.XR\.Oculus\.Input(?:\..+)*$
42+
type: Namespace
43+
- exclude:
44+
uidRegex: ^Unity\.XR\.GoogleVr(?:\..+)*$
45+
type: Namespace
46+
- exclude:
47+
uidRegex: ^Unity\.XR\.OpenVR(?:\..+)*$
48+
type: Namespace
49+
- exclude:
50+
uidRegex: ^UnityEngine\.XR\.WindowsMR\.Input(?:\..+)*$
51+
type: Namespace
52+
- exclude:
53+
uidRegex: ^UnityEngine\.InputSystem\.XR\.Haptics(?:\..+)*$
54+
type: Namespace
55+
- exclude:
56+
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRControllerWithRumble$
57+
type: Type
58+
- exclude:
59+
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRControllerWithRumble\..*$
60+
type: Member
61+
- exclude:
62+
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRSupport$
63+
type: Type
64+
- exclude:
65+
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRSupport\..*$
66+
type: Member
67+
- exclude:
68+
uidRegex: ^UnityEngine\.InputSystem\.XR\.FeatureType$
69+
type: Type
70+
- exclude:
71+
uidRegex: ^UnityEngine\.InputSystem\.XR\.UsageHint$
72+
type: Type
73+
- exclude:
74+
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRFeatureDescriptor$
75+
type: Type
76+
- exclude:
77+
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRDeviceDescriptor$
78+
type: Type
79+
- exclude:
80+
uidRegex: ^UnityEngine\.InputSystem\.XR\.Bone$
81+
type: Type
82+
- exclude:
83+
uidRegex: ^UnityEngine\.InputSystem\.XR\.Eyes$
84+
type: Type
85+
- exclude:
86+
uidRegex: ^UnityEngine\.InputSystem\.XR\.BoneControl$
87+
type: Type
88+
- exclude:
89+
uidRegex: ^UnityEngine\.InputSystem\.XR\.EyesControl$
90+
type: Type

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Devices/GoogleVR.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
1+
#if !DISABLE_BUILTIN_INPUT_SYSTEM_GOOGLEVR
22
// Docs generation is skipped because these are intended to be replaced with the com.unity.xr.googlevr package.
3-
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !DISABLE_BUILTIN_INPUT_SYSTEM_GOOGLEVR && !UNITY_FORCE_INPUTSYSTEM_XR_OFF && !PACKAGE_DOCS_GENERATION
43
using UnityEngine.InputSystem.Controls;
54
using UnityEngine.InputSystem.Layouts;
65
using UnityEngine.InputSystem.XR;

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Devices/Oculus.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
1+
#if !DISABLE_BUILTIN_INPUT_SYSTEM_OCULUS
22
// Docs generation is skipped because these are intended to be replaced with the com.unity.xr.oculus package.
3-
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !DISABLE_BUILTIN_INPUT_SYSTEM_OCULUS && !UNITY_FORCE_INPUTSYSTEM_XR_OFF && !PACKAGE_DOCS_GENERATION
43
using UnityEngine.InputSystem;
54
using UnityEngine.InputSystem.Controls;
65
using UnityEngine.InputSystem.Layouts;

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Devices/OpenVR.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
1+
#if !DISABLE_BUILTIN_INPUT_SYSTEM_OPENVR
22
// Docs generation is skipped because these are intended to be replaced with the com.unity.xr.openvr package.
3-
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !DISABLE_BUILTIN_INPUT_SYSTEM_OPENVR && !UNITY_FORCE_INPUTSYSTEM_XR_OFF && !PACKAGE_DOCS_GENERATION
43
using UnityEngine.InputSystem;
54
using UnityEngine.InputSystem.Controls;
65
using UnityEngine.InputSystem.Layouts;

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Devices/WindowsMR.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
1+
#if !DISABLE_BUILTIN_INPUT_SYSTEM_WINDOWSMR
22
// Docs generation is skipped because these are intended to be replaced with the com.unity.xr.windowsmr package.
3-
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !DISABLE_BUILTIN_INPUT_SYSTEM_WINDOWSMR && !UNITY_FORCE_INPUTSYSTEM_XR_OFF && !PACKAGE_DOCS_GENERATION
43
using UnityEngine.InputSystem.Controls;
54
using UnityEngine.InputSystem.Layouts;
65
using UnityEngine.InputSystem.XR;

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

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,71 @@
1-
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
2-
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !UNITY_FORCE_INPUTSYSTEM_XR_OFF || PACKAGE_DOCS_GENERATION
31
using UnityEngine.InputSystem.Controls;
42
using UnityEngine.InputSystem.XR.Haptics;
53
using UnityEngine.InputSystem.Layouts;
64
using UnityEngine.XR;
75

86
namespace UnityEngine.InputSystem.XR
97
{
8+
/// <summary>
9+
/// The base type of all XR head mounted displays. This can help organize shared behaviour across all HMDs.
10+
/// </summary>
11+
///
12+
/// <remarks>
13+
///
14+
/// To give your head tracking an extra update before rendering:
15+
/// First, enable before render updates on your Device.
16+
///
17+
/// // JSON
18+
/// {
19+
/// "name" : "MyHMD",
20+
/// "extend" : "HMD",
21+
/// "beforeRender" : "Update"
22+
/// }
23+
///
24+
/// Then, make sure you put extra `StateEvents` for your HMD on the queue right in time before rendering. Also, if your HMD is a combination of non-tracking and tracking controls, you can update just the tracking by sending a delta event instead of a full state event.
25+
///
26+
/// </remarks>
1027
[InputControlLayout(isGenericTypeOfDevice = true, displayName = "XR HMD", canRunInBackground = true)]
1128
public class XRHMD : TrackedDevice
1229
{
1330
/// <summary>
14-
/// The base type of all XR head mounted displays. This can help organize shared behaviour across all HMDs.
31+
/// Accessor for left eye position.
1532
/// </summary>
16-
///
17-
/// <remarks>
18-
///
19-
/// To give your head tracking an extra update before rendering:
20-
/// First, enable before render updates on your Device.
21-
///
22-
/// <sample>
23-
/// <code>
24-
/// // JSON
25-
/// {
26-
/// "name" : "MyHMD",
27-
/// "extend" : "HMD",
28-
/// "beforeRender" : "Update"
29-
/// }
30-
/// </code>
31-
/// </sample>
32-
///
33-
/// Then, make sure you put extra `StateEvents` for your HMD on the queue right in time before rendering. Also, if your HMD is a combination of non-tracking and tracking controls, you can update just the tracking by sending a delta event instead of a full state event.
34-
///
35-
/// </remarks>
36-
3733
[InputControl(noisy = true)]
3834
public Vector3Control leftEyePosition { get; protected set; }
35+
36+
/// <summary>
37+
/// Accessor for left eye rotation.
38+
/// </summary>
3939
[InputControl(noisy = true)]
4040
public QuaternionControl leftEyeRotation { get; protected set; }
41+
42+
/// <summary>
43+
/// Accessor for right eye position.
44+
/// </summary>
4145
[InputControl(noisy = true)]
4246
public Vector3Control rightEyePosition { get; protected set; }
47+
48+
/// <summary>
49+
/// Accessor for right eye rotation.
50+
/// </summary>
4351
[InputControl(noisy = true)]
4452
public QuaternionControl rightEyeRotation { get; protected set; }
53+
54+
/// <summary>
55+
/// Accessor for center eye position.
56+
/// </summary>
4557
[InputControl(noisy = true)]
4658
public Vector3Control centerEyePosition { get; protected set; }
59+
60+
/// <summary>
61+
/// Accessor for center eye rotation.
62+
/// </summary>
4763
[InputControl(noisy = true)]
4864
public QuaternionControl centerEyeRotation { get; protected set; }
4965

66+
/// <summary>
67+
/// Override for FinishSetup().
68+
/// </summary>
5069
protected override void FinishSetup()
5170
{
5271
base.FinishSetup();
@@ -72,22 +91,12 @@ public class XRController : TrackedDevice
7291
/// <remarks>
7392
/// If there is no left hand connected, this will be null.
7493
/// This also matches any currently tracked device that contains the 'LeftHand' device usage.
75-
/// <example>
76-
/// <code>
77-
/// // To set up an Action to specifically target
78-
/// // the left-hand XR controller:
79-
///
94+
/// To set up an Action to specifically target
95+
/// the left-hand XR controller:
8096
/// var action = new InputAction(binding: "/&lt;XRController&gt;{leftHand}/position");
81-
/// </code>
82-
/// </example>
83-
///
84-
/// <example>
85-
/// <code>
86-
/// // To make the left-hand XR controller behave like the right-hand one
97+
/// To make the left-hand XR controller behave like the right-hand one
8798
/// var controller = XRController.leftHand;
8899
/// InputSystem.SetUsage(controller, CommonUsages.RightHand);
89-
/// </code>
90-
/// </example>
91100
/// </remarks>
92101
public static XRController leftHand => InputSystem.GetDevice<XRController>(CommonUsages.LeftHand);
93102

@@ -97,10 +106,13 @@ public class XRController : TrackedDevice
97106
/// <remarks>If there is no left hand connected, this will be null. This also matches any currently tracked device that contains the 'RightHand' device usage.</remarks>
98107
public static XRController rightHand => InputSystem.GetDevice<XRController>(CommonUsages.RightHand);
99108

109+
/// <summary>
110+
/// Override for FinishSetup().
111+
/// </summary>
100112
protected override void FinishSetup()
101113
{
102114
base.FinishSetup();
103-
115+
#if UNITY_INPUT_SYSTEM_ENABLE_XR
104116
var capabilities = description.capabilities;
105117
var deviceDescriptor = XRDeviceDescriptor.FromJson(capabilities);
106118

@@ -111,6 +123,7 @@ protected override void FinishSetup()
111123
else if ((deviceDescriptor.characteristics & InputDeviceCharacteristics.Right) != 0)
112124
InputSystem.SetDeviceUsage(this, CommonUsages.RightHand);
113125
}
126+
#endif
114127
}
115128
}
116129

@@ -119,11 +132,15 @@ protected override void FinishSetup()
119132
/// </summary>
120133
public class XRControllerWithRumble : XRController
121134
{
135+
/// <summary>
136+
/// Sends an impulse command with the given amplitude and duration.
137+
/// </summary>
138+
/// <param name="amplitude"> Amplitude of the impulse.</param>
139+
/// <param name="duration"> Duration of the impulse.</param>
122140
public void SendImpulse(float amplitude, float duration)
123141
{
124142
var command = SendHapticImpulseCommand.Create(0, amplitude, duration);
125143
ExecuteCommand(ref command);
126144
}
127145
}
128146
}
129-
#endif

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Haptics/BufferedRumble.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
2-
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
31
namespace UnityEngine.InputSystem.XR.Haptics
42
{
53
public struct BufferedRumble
@@ -26,4 +24,3 @@ public void EnqueueRumble(byte[] samples)
2624
}
2725
}
2826
}
29-
#endif

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Haptics/GetCurrentHapticStateCommand.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
2-
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
31
using System.Runtime.InteropServices;
42
using UnityEngine.InputSystem.LowLevel;
53
using UnityEngine.InputSystem.Utilities;
@@ -47,4 +45,3 @@ public static GetCurrentHapticStateCommand Create()
4745
}
4846
}
4947
}
50-
#endif

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/Haptics/GetHapticCapabilitiesCommand.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
2-
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
31
using System.Runtime.InteropServices;
42
using UnityEngine.InputSystem.LowLevel;
53
using UnityEngine.InputSystem.Utilities;
@@ -156,4 +154,3 @@ public static GetHapticCapabilitiesCommand Create()
156154
}
157155
}
158156
}
159-
#endif

0 commit comments

Comments
 (0)