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 2 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
12 changes: 12 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,15 @@ 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: ^Unity\.XR\.WindowsMR\.Input\..*$
type: Namespace
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,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 || PACKAGE_DOCS_GENERATION
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.XR.Haptics;
using UnityEngine.InputSystem.Layouts;
Expand Down Expand Up @@ -100,7 +98,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 +109,7 @@ protected override void FinishSetup()
else if ((deviceDescriptor.characteristics & InputDeviceCharacteristics.Right) != 0)
InputSystem.SetDeviceUsage(this, CommonUsages.RightHand);
}
#endif
}
}

Expand All @@ -126,4 +125,3 @@ public void SendImpulse(float amplitude, float duration)
}
}
}
#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,7 +102,12 @@ 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>
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