diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index f64be23383..cabb936869 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed InputSystem.onAnyButtonPress fails to trigger when the device receives a touch [UUM-137930](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-137930). - Fixed an incorrect ArraysHelper.HaveDuplicateReferences implementation that didn't use its arguments right [ISXB-1792] (https://github.com/Unity-Technologies/InputSystem/pull/2376) - Fixed `InputAction.IsPressed`, `WasPressedThisFrame`, and `WasReleasedThisFrame` using a `ButtonControl`'s `pressPoint` when a binding also had an explicit `PressInteraction` with its own `pressPoint`, which could make those APIs disagree with the interaction's press and release behavior. Action-level press APIs now follow the interaction threshold when both are set explicitly. +- Replaced deprecated `DEVELOPMENT_BUILD` and `UNITY_64` preprocessor directives flagged by the `UAC0008` / `UAC0009` analyzers on Unity 6000.6 (Package Validation rule `PVP-301-1`). `#if DEVELOPMENT_BUILD || UNITY_EDITOR` becomes `#if UNITY_EDITOR || DEBUG` (`DEBUG` is the modern managed-code-variant equivalent that's defined in development player builds), `#if UNITY_64` becomes a runtime `IntPtr.Size == 8` check. Also added `[NonSerialized]` on `HID.HIDLayoutBuilder.deviceType` and `HID.HIDElementDescriptor.usageMin` / `usageMax` to silence `UAC1001`. No behavioural change. ### Changed - Action-level `IsPressed`, `WasPressedThisFrame`, and `WasReleasedThisFrame` for bindings to `Vector2Control` / `StickControl` no longer consult a per-control `pressPoint` on the vector (that field was removed). Use a `Press` interaction to set a custom threshold, or rely on `defaultButtonPressPoint`. diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlExtensions.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlExtensions.cs index 32955d8716..7072548885 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlExtensions.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlExtensions.cs @@ -1616,7 +1616,7 @@ public struct ControlBuilder [MethodImpl(MethodImplOptions.AggressiveInlining)] public ControlBuilder At(InputDevice device, int index) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (device == null) throw new ArgumentNullException(nameof(device)); if (index < 0 || index >= device.m_ChildrenForEachControl.Length) @@ -1630,7 +1630,7 @@ public ControlBuilder At(InputDevice device, int index) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ControlBuilder WithParent(InputControl parent) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (parent == null) throw new ArgumentNullException(nameof(parent)); if (parent == control) @@ -1643,7 +1643,7 @@ public ControlBuilder WithParent(InputControl parent) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ControlBuilder WithName(string name) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name)); #endif @@ -1654,7 +1654,7 @@ public ControlBuilder WithName(string name) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ControlBuilder WithDisplayName(string displayName) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (string.IsNullOrEmpty(displayName)) throw new ArgumentNullException(nameof(displayName)); #endif @@ -1665,7 +1665,7 @@ public ControlBuilder WithDisplayName(string displayName) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ControlBuilder WithShortDisplayName(string shortDisplayName) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (string.IsNullOrEmpty(shortDisplayName)) throw new ArgumentNullException(nameof(shortDisplayName)); #endif @@ -1676,7 +1676,7 @@ public ControlBuilder WithShortDisplayName(string shortDisplayName) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ControlBuilder WithLayout(InternedString layout) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (layout.IsEmpty()) throw new ArgumentException("Layout name cannot be empty", nameof(layout)); #endif @@ -1687,7 +1687,7 @@ public ControlBuilder WithLayout(InternedString layout) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ControlBuilder WithUsages(int startIndex, int count) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (startIndex < 0 || startIndex >= control.device.m_UsagesForEachControl.Length) throw new ArgumentOutOfRangeException(nameof(startIndex)); if (count < 0 || startIndex + count > control.device.m_UsagesForEachControl.Length) @@ -1701,7 +1701,7 @@ public ControlBuilder WithUsages(int startIndex, int count) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ControlBuilder WithAliases(int startIndex, int count) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (startIndex < 0 || startIndex >= control.device.m_AliasesForEachControl.Length) throw new ArgumentOutOfRangeException(nameof(startIndex)); if (count < 0 || startIndex + count > control.device.m_AliasesForEachControl.Length) @@ -1715,7 +1715,7 @@ public ControlBuilder WithAliases(int startIndex, int count) [MethodImpl(MethodImplOptions.AggressiveInlining)] public ControlBuilder WithChildren(int startIndex, int count) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (startIndex < 0 || startIndex >= control.device.m_ChildrenForEachControl.Length) throw new ArgumentOutOfRangeException(nameof(startIndex)); if (count < 0 || startIndex + count > control.device.m_ChildrenForEachControl.Length) @@ -1754,7 +1754,7 @@ public ControlBuilder WithProcessor(TProcessor processor) where TValue : struct where TProcessor : InputProcessor { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (processor == null) throw new ArgumentNullException(nameof(processor)); #endif @@ -1808,7 +1808,7 @@ public struct DeviceBuilder [MethodImpl(MethodImplOptions.AggressiveInlining)] public DeviceBuilder WithName(string name) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name)); #endif @@ -1819,7 +1819,7 @@ public DeviceBuilder WithName(string name) [MethodImpl(MethodImplOptions.AggressiveInlining)] public DeviceBuilder WithDisplayName(string displayName) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (string.IsNullOrEmpty(displayName)) throw new ArgumentNullException(nameof(displayName)); #endif @@ -1830,7 +1830,7 @@ public DeviceBuilder WithDisplayName(string displayName) [MethodImpl(MethodImplOptions.AggressiveInlining)] public DeviceBuilder WithShortDisplayName(string shortDisplayName) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (string.IsNullOrEmpty(shortDisplayName)) throw new ArgumentNullException(nameof(shortDisplayName)); #endif @@ -1841,7 +1841,7 @@ public DeviceBuilder WithShortDisplayName(string shortDisplayName) [MethodImpl(MethodImplOptions.AggressiveInlining)] public DeviceBuilder WithLayout(InternedString layout) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (layout.IsEmpty()) throw new ArgumentException("Layout name cannot be empty", nameof(layout)); #endif @@ -1852,7 +1852,7 @@ public DeviceBuilder WithLayout(InternedString layout) [MethodImpl(MethodImplOptions.AggressiveInlining)] public DeviceBuilder WithChildren(int startIndex, int count) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (startIndex < 0 || startIndex >= device.device.m_ChildrenForEachControl.Length) throw new ArgumentOutOfRangeException(nameof(startIndex)); if (count < 0 || startIndex + count > device.device.m_ChildrenForEachControl.Length) @@ -1880,7 +1880,7 @@ public DeviceBuilder IsNoisy(bool value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public DeviceBuilder WithControlUsage(int controlIndex, InternedString usage, InputControl control) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (controlIndex < 0 || controlIndex >= device.m_UsagesForEachControl.Length) throw new ArgumentOutOfRangeException(nameof(controlIndex)); if (usage.IsEmpty()) @@ -1896,7 +1896,7 @@ public DeviceBuilder WithControlUsage(int controlIndex, InternedString usage, In [MethodImpl(MethodImplOptions.AggressiveInlining)] public DeviceBuilder WithControlAlias(int controlIndex, InternedString alias) { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG if (controlIndex < 0 || controlIndex >= device.m_AliasesForEachControl.Length) throw new ArgumentOutOfRangeException(nameof(controlIndex)); if (alias.IsEmpty()) diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlList.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlList.cs index 92f123ac2e..32a66cacc6 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlList.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/Controls/InputControlList.cs @@ -45,7 +45,7 @@ namespace UnityEngine.InputSystem /// /// Type of to store in the list. [DebuggerDisplay("Count = {Count}")] - #if UNITY_EDITOR || DEVELOPMENT_BUILD + #if UNITY_EDITOR || DEBUG [DebuggerTypeProxy(typeof(InputControlListDebugView<>))] #endif public unsafe struct InputControlList : IList, IReadOnlyList, IDisposable @@ -597,7 +597,7 @@ public void Dispose() } } - #if UNITY_EDITOR || DEVELOPMENT_BUILD + #if UNITY_EDITOR || DEBUG internal struct InputControlListDebugView where TControl : InputControl { diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/Devices/Remote/InputRemoting.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/Devices/Remote/InputRemoting.cs index 2d4ecb5eb9..bc4002ad65 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/Devices/Remote/InputRemoting.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/Devices/Remote/InputRemoting.cs @@ -757,7 +757,7 @@ private static TData DeserializeData(byte[] data) return JsonUtility.FromJson(json); } -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG // State we want to take across domain reloads. We can only take some of the // state across. Subscriptions will be lost and have to be manually restored. [Serializable] diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/Events/InputEventBuffer.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/Events/InputEventBuffer.cs index 872b4e93bb..67f134c67e 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/Events/InputEventBuffer.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/Events/InputEventBuffer.cs @@ -298,7 +298,7 @@ internal void AdvanceToNextEvent(ref InputEvent* currentReadPos, if (numRemainingEvents > 1) { // Don't perform safety check in non-debug builds. - #if UNITY_EDITOR || DEVELOPMENT_BUILD + #if UNITY_EDITOR || DEBUG newReadPos = InputEvent.GetNextInMemoryChecked(currentReadPos, ref this); #else newReadPos = InputEvent.GetNextInMemory(currentReadPos); diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.cs index e7f6cd9ee9..1dff2e4330 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/InputManager.cs @@ -4481,7 +4481,7 @@ private bool FlipBuffersForDeviceIfNecessary(InputDevice device, InputUpdateType // Stuff everything that we want to survive a domain reload into // a m_SerializedState. - #if UNITY_EDITOR || DEVELOPMENT_BUILD + #if UNITY_EDITOR || DEBUG [Serializable] internal struct DeviceState { @@ -4795,6 +4795,6 @@ private bool RestoreDeviceFromSavedState(ref DeviceState deviceState, InternedSt return true; } -#endif // UNITY_EDITOR || DEVELOPMENT_BUILD +#endif // UNITY_EDITOR || DEBUG } } diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/InputSystem.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/InputSystem.cs index 1864b5d421..4fc50b9b39 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/InputSystem.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/InputSystem.cs @@ -3366,7 +3366,7 @@ public static bool runInBackground internal static InputManager s_Manager; internal static InputRemoting s_Remote; -#if DEVELOPMENT_BUILD || UNITY_EDITOR +#if UNITY_EDITOR || DEBUG private static RemoteInputPlayerConnection s_RemoteConnection; internal static RemoteInputPlayerConnection remoteConnection @@ -3411,7 +3411,7 @@ private static bool ShouldEnableRemoting() } #endif //!UNITY_EDITOR -#endif // DEVELOPMENT_BUILD || UNITY_EDITOR +#endif // UNITY_EDITOR || DEBUG // The rest here is internal stuff to manage singletons, survive domain reloads, // and to support the reset ability for tests. @@ -3506,7 +3506,7 @@ internal static void InitializeInPlayer(IInputRuntime runtime = null, bool loadS #endif // Automatically enable remoting in development players. - #if DEVELOPMENT_BUILD + #if !UNITY_EDITOR && DEBUG if (ShouldEnableRemoting()) SetUpRemoting(); #endif diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/InputSystemState.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/InputSystemState.cs index b42cd90786..25150fb3a9 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/InputSystemState.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/InputSystemState.cs @@ -5,7 +5,7 @@ namespace UnityEngine.InputSystem { -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR || DEBUG /// /// Snapshot of the state used by the input system. /// diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/EnhancedTouch/EnhancedTouchSupport.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/EnhancedTouch/EnhancedTouchSupport.cs index 637c614446..f41c8299fa 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/EnhancedTouch/EnhancedTouchSupport.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/EnhancedTouch/EnhancedTouchSupport.cs @@ -202,7 +202,7 @@ private static void OnBeforeDomainReload() #endif - [Conditional("DEVELOPMENT_BUILD")] + [Conditional("DEBUG")] [Conditional("UNITY_EDITOR")] internal static void CheckEnabled() { diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/HID/HID.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/HID/HID.cs index 9becfbe872..b3bbacb945 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/HID/HID.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/HID/HID.cs @@ -323,7 +323,7 @@ private class HIDLayoutBuilder public string displayName; public HIDDeviceDescriptor hidDescriptor; public string parentLayout; - public Type deviceType; + [NonSerialized] public Type deviceType; public InputControlLayout Build() { @@ -517,8 +517,8 @@ public struct HIDElementDescriptor public HIDElementFlags flags; // Fields only relevant to arrays. - public int? usageMin; - public int? usageMax; + [NonSerialized] public int? usageMin; + [NonSerialized] public int? usageMax; public bool hasNullState => (flags & HIDElementFlags.NullState) == HIDElementFlags.NullState; diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/PlayerInput/PlayerInputManager.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/PlayerInput/PlayerInputManager.cs index 28f9338f61..7bb656bdcd 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/PlayerInput/PlayerInputManager.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/Plugins/PlayerInput/PlayerInputManager.cs @@ -706,7 +706,7 @@ private bool IsDeviceUsableWithPlayerActions(InputDevice device) private void ValidateInputActionAsset() { -#if DEVELOPMENT_BUILD || UNITY_EDITOR +#if UNITY_EDITOR || DEBUG if (m_PlayerPrefab == null || m_PlayerPrefab.GetComponentInChildren() == null) return; diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/State/InputStateBuffers.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/State/InputStateBuffers.cs index eae5349bbe..0299b85bae 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/State/InputStateBuffers.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/State/InputStateBuffers.cs @@ -330,7 +330,7 @@ private static void MigrateDoubleBuffer(DoubleBuffers newBuffer, InputDevice[] d // NOTE: This also means that device indices of if (device.m_StateBlock.byteOffset == InputStateBlock.InvalidOffset) { - #if DEVELOPMENT_BUILD || UNITY_EDITOR + #if UNITY_EDITOR || DEBUG for (var n = i + 1; n < deviceCount; ++n) Debug.Assert(devices[n].m_StateBlock.byteOffset == InputStateBlock.InvalidOffset, "New devices must be appended to the array; found an old device coming in the array after a newly added device"); diff --git a/Packages/com.unity.inputsystem/InputSystem/Runtime/Utilities/MemoryHelpers.cs b/Packages/com.unity.inputsystem/InputSystem/Runtime/Utilities/MemoryHelpers.cs index 21ad623ef2..a51ff665ac 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Runtime/Utilities/MemoryHelpers.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Runtime/Utilities/MemoryHelpers.cs @@ -241,16 +241,17 @@ public static void MemSet(void* destination, int numBytes, byte value) unchecked { - // 64bit blocks. - #if UNITY_64 - while (numBytes >= 8) + // 64bit blocks (only on 64-bit runtimes; JIT folds the branch). + if (IntPtr.Size == 8) { - *(ulong*)&to[pos] = ((ulong)value << 56) | ((ulong)value << 48) | ((ulong)value << 40) | ((ulong)value << 32) - | ((ulong)value << 24) | ((ulong)value << 16) | ((ulong)value << 8) | value; - numBytes -= 8; - pos += 8; + while (numBytes >= 8) + { + *(ulong*)&to[pos] = ((ulong)value << 56) | ((ulong)value << 48) | ((ulong)value << 40) | ((ulong)value << 32) + | ((ulong)value << 24) | ((ulong)value << 16) | ((ulong)value << 8) | value; + numBytes -= 8; + pos += 8; + } } - #endif // 32bit blocks. while (numBytes >= 4) @@ -287,16 +288,17 @@ public static void MemCpyMasked(void* destination, void* source, int numBytes, v unchecked { - // Copy 64bit blocks. - #if UNITY_64 - while (numBytes >= 8) + // Copy 64bit blocks (only on 64-bit runtimes; JIT folds the branch). + if (IntPtr.Size == 8) { - *(ulong*)(to + pos) &= ~*(ulong*)(bits + pos); // Preserve unmasked bits. - *(ulong*)(to + pos) |= *(ulong*)(from + pos) & *(ulong*)(bits + pos); // Copy masked bits. - numBytes -= 8; - pos += 8; + while (numBytes >= 8) + { + *(ulong*)(to + pos) &= ~*(ulong*)(bits + pos); // Preserve unmasked bits. + *(ulong*)(to + pos) |= *(ulong*)(from + pos) & *(ulong*)(bits + pos); // Copy masked bits. + numBytes -= 8; + pos += 8; + } } - #endif // Copy 32bit blocks. while (numBytes >= 4)