Skip to content

CHANGE: Refactor class conditional guards #2183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ however, it has to be formatted properly to pass verification tests.

### Changed
- Changed enum value `Key.IMESelected` to obsolete which was not a real key. Please use the ButtonControl `imeSelected`.
- 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.

### Added
- Added support of F13-F24 keys. [UUM-44328](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-44328)
Expand Down
51 changes: 51 additions & 0 deletions Packages/com.unity.inputsystem/Documentation~/filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,54 @@ apiRules:
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.InputSystem\.runInBackground$
type: Member
- exclude:
uidRegex: ^Unity\.XR\.Oculus\.Input(?:\..+)*$
type: Namespace
- exclude:
uidRegex: ^Unity\.XR\.GoogleVr(?:\..+)*$
type: Namespace
- exclude:
uidRegex: ^Unity\.XR\.OpenVR(?:\..+)*$
type: Namespace
- exclude:
uidRegex: ^UnityEngine\.XR\.WindowsMR\.Input(?:\..+)*$
type: Namespace
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.Haptics(?:\..+)*$
type: Namespace
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRControllerWithRumble$
type: Type
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRControllerWithRumble\..*$
type: Member
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRSupport$
type: Type
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRSupport\..*$
type: Member
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.FeatureType$
type: Type
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.UsageHint$
type: Type
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRFeatureDescriptor$
type: Type
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.XRDeviceDescriptor$
type: Type
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.Bone$
type: Type
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.Eyes$
type: Type
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.BoneControl$
type: Type
- exclude:
uidRegex: ^UnityEngine\.InputSystem\.XR\.EyesControl$
type: Type
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if !DISABLE_BUILTIN_INPUT_SYSTEM_GOOGLEVR
// Docs generation is skipped because these are intended to be replaced with the com.unity.xr.googlevr package.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !DISABLE_BUILTIN_INPUT_SYSTEM_GOOGLEVR && !UNITY_FORCE_INPUTSYSTEM_XR_OFF && !PACKAGE_DOCS_GENERATION
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.XR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if !DISABLE_BUILTIN_INPUT_SYSTEM_OCULUS
// Docs generation is skipped because these are intended to be replaced with the com.unity.xr.oculus package.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !DISABLE_BUILTIN_INPUT_SYSTEM_OCULUS && !UNITY_FORCE_INPUTSYSTEM_XR_OFF && !PACKAGE_DOCS_GENERATION
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if !DISABLE_BUILTIN_INPUT_SYSTEM_OPENVR
// Docs generation is skipped because these are intended to be replaced with the com.unity.xr.openvr package.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !DISABLE_BUILTIN_INPUT_SYSTEM_OPENVR && !UNITY_FORCE_INPUTSYSTEM_XR_OFF && !PACKAGE_DOCS_GENERATION
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if !DISABLE_BUILTIN_INPUT_SYSTEM_WINDOWSMR
// Docs generation is skipped because these are intended to be replaced with the com.unity.xr.windowsmr package.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !DISABLE_BUILTIN_INPUT_SYSTEM_WINDOWSMR && !UNITY_FORCE_INPUTSYSTEM_XR_OFF && !PACKAGE_DOCS_GENERATION
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.XR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !UNITY_FORCE_INPUTSYSTEM_XR_OFF || PACKAGE_DOCS_GENERATION
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.XR.Haptics;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.XR;

namespace UnityEngine.InputSystem.XR
{
/// <summary>
/// The base type for all XR head mounted displays.
/// </summary>
[InputControlLayout(isGenericTypeOfDevice = true, displayName = "XR HMD", canRunInBackground = true)]
public class XRHMD : TrackedDevice
{
Expand Down Expand Up @@ -34,16 +35,39 @@ public class XRHMD : TrackedDevice
///
/// </remarks>

/// <summary>
/// Accessor for left eye position.
/// </summary>
[InputControl(noisy = true)]
public Vector3Control leftEyePosition { get; protected set; }

/// <summary>
/// Accessor for left eye rotation.
/// </summary>
[InputControl(noisy = true)]
public QuaternionControl leftEyeRotation { get; protected set; }
[InputControl(noisy = true)]

/// <summary>
/// Accessor for right eye position.
/// </summary>
public Vector3Control rightEyePosition { get; protected set; }
[InputControl(noisy = true)]

/// <summary>
/// Accessor for right eye rotation.
/// </summary>
public QuaternionControl rightEyeRotation { get; protected set; }

/// <summary>
/// Accessor for center eye position.
/// </summary>
[InputControl(noisy = true)]
public Vector3Control centerEyePosition { get; protected set; }

/// <summary>
/// Accessor for center eye rotation.
/// </summary>
[InputControl(noisy = true)]
public QuaternionControl centerEyeRotation { get; protected set; }

Expand Down Expand Up @@ -100,7 +124,7 @@ public class XRController : TrackedDevice
protected override void FinishSetup()
{
base.FinishSetup();

#if UNITY_INPUT_SYSTEM_ENABLE_XR
var capabilities = description.capabilities;
var deviceDescriptor = XRDeviceDescriptor.FromJson(capabilities);

Expand All @@ -111,6 +135,7 @@ protected override void FinishSetup()
else if ((deviceDescriptor.characteristics & InputDeviceCharacteristics.Right) != 0)
InputSystem.SetDeviceUsage(this, CommonUsages.RightHand);
}
#endif
}
}

Expand All @@ -119,11 +144,15 @@ protected override void FinishSetup()
/// </summary>
public class XRControllerWithRumble : XRController
{
/// <summary>
/// Sends an impulse command with the given amplitude and duration.
/// </summary>
/// <param name="amplitude"> Amplitude of the impulse.</param>
/// <param name="duration"> Duration of the impulse.</param>
public void SendImpulse(float amplitude, float duration)
{
var command = SendHapticImpulseCommand.Create(0, amplitude, duration);
ExecuteCommand(ref command);
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
namespace UnityEngine.InputSystem.XR.Haptics
{
public struct BufferedRumble
Expand All @@ -26,4 +24,3 @@ public void EnqueueRumble(byte[] samples)
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
Expand Down Expand Up @@ -47,4 +45,3 @@ public static GetCurrentHapticStateCommand Create()
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
Expand Down Expand Up @@ -156,4 +154,3 @@ public static GetHapticCapabilitiesCommand Create()
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
Expand Down Expand Up @@ -53,4 +51,3 @@ public static SendBufferedHapticCommand Create(byte[] rumbleBuffer)
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
Expand Down Expand Up @@ -50,4 +48,3 @@ public static SendHapticImpulseCommand Create(int motorChannel, float motorAmpli
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !UNITY_FORCE_INPUTSYSTEM_XR_OFF
using System;
using System.Collections.Generic;
using UnityEngine.InputSystem.LowLevel;
Expand Down Expand Up @@ -90,7 +88,7 @@ internal static string OnFindLayoutForDevice(ref InputDeviceDescription descript
{
return null;
}

#if UNITY_INPUT_SYSTEM_ENABLE_XR
if (string.IsNullOrEmpty(matchedLayout))
{
const InputDeviceCharacteristics controllerCharacteristics = InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Controller;
Expand All @@ -99,7 +97,7 @@ internal static string OnFindLayoutForDevice(ref InputDeviceDescription descript
else if ((deviceDescriptor.characteristics & controllerCharacteristics) == controllerCharacteristics)
matchedLayout = "XRController";
}

#endif
string layoutName;
if (string.IsNullOrEmpty(description.manufacturer))
{
Expand Down Expand Up @@ -341,4 +339,3 @@ private InputControlLayout Build()
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ENABLE_VR is not defined on Game Core but the assembly is available with limited features when the XR module is enabled.
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) || PACKAGE_DOCS_GENERATION
using System;
using System.Collections.Generic;
using UnityEngine.InputSystem.Layouts;
Expand Down Expand Up @@ -104,20 +102,25 @@ public class XRDeviceDescriptor
/// <summary>
/// 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).
/// </summary>
#if UNITY_INPUT_SYSTEM_ENABLE_XR
public InputDeviceCharacteristics characteristics;
#else
[SerializeField]
private uint characteristics;
#endif
/// <summary>
/// The underlying deviceId, this can be used with <see cref="UnityEngine.XR.InputDevices"/> to create a device.
/// </summary>
public int deviceId;
/// <summary>
/// A list of all input features. <seealso cref="XRFeatureDescriptor"/>
/// A list of all input features. <see cref="XRFeatureDescriptor"/>
/// </summary>
public List<XRFeatureDescriptor> inputFeatures;

/// <summary>
/// Converts this structure to a JSON string.
/// </summary>
/// <returns></returns>
/// <returns>A JSON string.</returns>
public string ToJson()
{
return JsonUtility.ToJson(this);
Expand Down Expand Up @@ -388,7 +391,7 @@ static class XRSupport
/// </summary>
public static void Initialize()
{
#if !UNITY_FORCE_INPUTSYSTEM_XR_OFF
#if UNITY_INPUT_SYSTEM_ENABLE_XR && (ENABLE_VR || UNITY_GAMECORE) && !UNITY_FORCE_INPUTSYSTEM_XR_OFF
InputSystem.RegisterLayout<PoseControl>("Pose");
InputSystem.RegisterLayout<BoneControl>("Bone");
InputSystem.RegisterLayout<EyesControl>("Eyes");
Expand Down Expand Up @@ -506,4 +509,3 @@ public static void Initialize()
}
}
}
#endif