diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 40777612e7..9424d1dc07 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,9 +6,13 @@ _Please fill this section with a description what the pull request is trying to _Please write down a short description of what changes were made._ -### Notes +### Testing -_Please write down any additional notes, remove the section if not applicable._ +_Please describe the testing already done by you and what testing you request/recommend QA to execute. If you used or created any testing project please link them here too for QA._ + +### Risk + +_Please describe the potential risks of your changes for the reviewers._ ### Checklist @@ -17,8 +21,8 @@ Before review: - [ ] Changelog entry added. - Explains the change in `Changed`, `Fixed`, `Added` sections. - For API change contains an example snippet and/or migration example. - - FogBugz ticket attached, example `([case %number%](https://issuetracker.unity3d.com/issues/...))`. - - FogBugz is marked as "Resolved" with *next* release version correctly set. + - JIRA ticket linked, example ([case %%](https://issuetracker.unity3d.com/product/unity/issues/guid/)). If it is a private issue, just add the case ID without a link. + - Jira port for the next release set as "Resolved". - [ ] Tests added/changed, if applicable. - Functional tests `Area_CanDoX`, `Area_CanDoX_EvenIfYIsTheCase`, `Area_WhenIDoX_AndYHappens_ThisIsTheResult`. - Performance tests. diff --git a/Assets/Samples/InGameHints/InGameHintsActions.cs b/Assets/Samples/InGameHints/InGameHintsActions.cs index 2328145186..44de75a137 100644 --- a/Assets/Samples/InGameHints/InGameHintsActions.cs +++ b/Assets/Samples/InGameHints/InGameHintsActions.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator -// version 1.8.3 +// version 1.9.0 // from Assets/Samples/InGameHints/InGameHintsActions.inputactions // // Changes to this file may cause incorrect behavior and will be lost if diff --git a/Assets/Samples/SimpleDemo/SimpleControls.cs b/Assets/Samples/SimpleDemo/SimpleControls.cs index 215643a27f..7b4a98ed3e 100644 --- a/Assets/Samples/SimpleDemo/SimpleControls.cs +++ b/Assets/Samples/SimpleDemo/SimpleControls.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator -// version 1.8.3 +// version 1.9.0 // from Assets/Samples/SimpleDemo/SimpleControls.inputactions // // Changes to this file may cause incorrect behavior and will be lost if diff --git a/Assets/Tests/InputSystem/CorePerformanceTests.cs b/Assets/Tests/InputSystem/CorePerformanceTests.cs index 80a0c5f6db..028008e85c 100644 --- a/Assets/Tests/InputSystem/CorePerformanceTests.cs +++ b/Assets/Tests/InputSystem/CorePerformanceTests.cs @@ -828,7 +828,7 @@ public void Performance_OptimizedControls_EvaluateStaleControlReadsWhenGamepadSt #endif return; - void MethodToMeasure(Gamepad gamepad) + void MethodToMeasure(Gamepad g) { var value2d = Vector2.zero; @@ -836,7 +836,7 @@ void MethodToMeasure(Gamepad gamepad) { // Make sure state changes are different from previous state so that we mark the controls as // stale. - InputSystem.QueueStateEvent(gamepad, + InputSystem.QueueStateEvent(g, new GamepadState { leftStick = new Vector2(i / 1000f, i / 1000f), diff --git a/Assets/Tests/InputSystem/CoreTests_Actions.cs b/Assets/Tests/InputSystem/CoreTests_Actions.cs index c4ae3b7c5d..00e2f5747b 100644 --- a/Assets/Tests/InputSystem/CoreTests_Actions.cs +++ b/Assets/Tests/InputSystem/CoreTests_Actions.cs @@ -30,6 +30,34 @@ // in terms of complexity. partial class CoreTests { + // ISXB-925: Feature flag values should live with containing settings instance. + [TestCase(InputFeatureNames.kUseReadValueCaching)] + [TestCase(InputFeatureNames.kUseOptimizedControls)] + [TestCase(InputFeatureNames.kParanoidReadValueCachingChecks)] + [TestCase(InputFeatureNames.kDisableUnityRemoteSupport)] + [TestCase(InputFeatureNames.kRunPlayerUpdatesInEditMode)] + #if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS + [TestCase(InputFeatureNames.kUseIMGUIEditorForAssets)] + #endif + public void Settings_ShouldStoreSettingsAndFeatureFlags(string featureName) + { + using (var settings = Scoped.Object(InputSettings.CreateInstance())) + { + InputSystem.settings = settings.value; + + Assert.That(InputSystem.settings.IsFeatureEnabled(featureName), Is.False); + settings.value.SetInternalFeatureFlag(featureName, true); + Assert.That(InputSystem.settings.IsFeatureEnabled(featureName), Is.True); + + using (var other = Scoped.Object(InputSettings.CreateInstance())) + { + InputSystem.settings = other.value; + + Assert.That(InputSystem.settings.IsFeatureEnabled(featureName), Is.False); + } + } + } + [Test] [Category("Actions")] public void Actions_WhenShortcutsDisabled_AllConflictingActionsTrigger() diff --git a/Assets/Tests/InputSystem/InputActionCodeGeneratorActions.cs b/Assets/Tests/InputSystem/InputActionCodeGeneratorActions.cs index 3d2576eb57..3784cca795 100644 --- a/Assets/Tests/InputSystem/InputActionCodeGeneratorActions.cs +++ b/Assets/Tests/InputSystem/InputActionCodeGeneratorActions.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator -// version 1.8.3 +// version 1.9.0 // from Assets/Tests/InputSystem/InputActionCodeGeneratorActions.inputactions // // Changes to this file may cause incorrect behavior and will be lost if diff --git a/Assets/Tests/InputSystem/Plugins/DualShockTests.cs b/Assets/Tests/InputSystem/Plugins/DualShockTests.cs index 50ec36aad6..8998758b2f 100644 --- a/Assets/Tests/InputSystem/Plugins/DualShockTests.cs +++ b/Assets/Tests/InputSystem/Plugins/DualShockTests.cs @@ -177,6 +177,25 @@ public void Devices_SupportsDualShockAsHID_WithJustPIDAndVID(int vendorId, int p Assert.That(device, Is.AssignableTo()); } + [Test] + [Category("Devices")] + [TestCase(0x54C, 0xCE6)] + [TestCase(0x54C, 0xDF2)] //Dualsense Edge + public void Devices_SupportsDualsenseAsHID_WithJustPIDAndVID(int vendorId, int productId) + { + var device = InputSystem.AddDevice(new InputDeviceDescription + { + interfaceName = "HID", + capabilities = new HID.HIDDeviceDescriptor + { + vendorId = vendorId, + productId = productId, + }.ToJson() + }); + + Assert.That(device, Is.AssignableTo()); + } + #if UNITY_WSA [Test] [Category("Devices")] diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 4dc3ca5256..2c39ec0385 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -10,6 +10,10 @@ however, it has to be formatted properly to pass verification tests. ## [Unreleased] - yyyy-mm-dd +### Change +- Added warning messages to both `OnScreenStick` and `OnScreenButton` Inspector editors that would display a warning message in case on-screen control components are added to a `GameObject` not part of a valid UI hierarchy. +- Changed behavior for internal feature flag relating to Windows Gaming Input to be ignored on non-supported platforms. + ### Fixed - Avoid potential crashes from `NullReferenceException` in `FireStateChangeNotifications`. - Fixed an issue where a composite binding would not be consecutively triggered after ResetDevice() has been called from the associated action handler [ISXB-746](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-746). @@ -19,12 +23,21 @@ however, it has to be formatted properly to pass verification tests. - Fixed error thrown when Cancelling Control Scheme creation in Input Actions Editor. - Fixed Scheme Name in Control Scheme editor menu that gets reset when editing devices [ISXB-763](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-763). - Fixed an issue where `InputActionAsset.FindAction(string, bool)` would throw `System.NullReferenceException` instead of returning `null` if searching for a non-existent action with an explicit action path and using `throwIfNotFound: false`, e.g. searching for "Map/Action" when `InputActionMap` "Map" exists but no `InputAction` named "Action" exists within that map [ISXB-895](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-895). +- Fixed an issue where adding a `OnScreenButton` or `OnScreenStick` to a regular GameObject would lead to exception in editor. +- Fixed an issue where adding a `OnScreenStick` to a regular GameObject and entering play-mode would lead to exceptions being generated. +- Fixed InputActionReference issues when domain reloads are disabled [ISXB-601](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-601), [ISXB-718](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-718), [ISXB-900](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-900) +- Fixed a performance issue with many objects using multiple action maps [ISXB-573](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-573). +- Fixed an variable scope shadowing issue causing compilation to fail on Unity 2019 LTS. +- Fixed an issue where changing `InputSettings` instance would not affect associated feature flags. -## Added +### Added - Added additional device information when logging the error due to exceeding the maximum number of events processed set by `InputSystem.settings.maxEventsBytesPerUpdate`. This additional information is available in development builds only. +### Changed +- Changed `DualSenseHIDInputReport` from internal to public visibility + ## [1.8.2] - 2024-04-29 ### Added diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionMap.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionMap.cs index d26eb8f251..8918757d89 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionMap.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionMap.cs @@ -318,6 +318,7 @@ public event Action actionTriggered /// public InputActionMap() { + s_NeedToResolveBindings = true; } /// @@ -810,6 +811,7 @@ private enum Flags } internal static int s_DeferBindingResolution; + internal static bool s_NeedToResolveBindings; internal struct DeviceArray { @@ -1193,6 +1195,9 @@ internal bool LazyResolveBindings(bool fullResolve) m_ControlsForEachAction = null; controlsForEachActionInitialized = false; + // Indicate that there is at least one action map that has a change + s_NeedToResolveBindings = true; + // If we haven't had to resolve bindings yet, we can wait until when we // actually have to. if (m_State == null) @@ -1982,6 +1987,9 @@ public void OnBeforeSerialize() /// public void OnAfterDeserialize() { + // Indicate that there is at least one action map that has a change + s_NeedToResolveBindings = true; + m_State = null; m_MapIndexInState = InputActionState.kInvalidIndex; m_EnabledActionsCount = 0; diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionReference.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionReference.cs index 73a73cd68e..5b56e431a9 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionReference.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionReference.cs @@ -199,6 +199,24 @@ public static InputActionReference Create(InputAction action) return reference; } + /// + /// Clears the cached field for all current objects. + /// + /// + /// After calling this, the next call to will retrieve a new reference from the existing just as if + /// using it for the first time. The serialized and fields are not touched and will continue to hold their current values. + /// + /// This method is used to clear the Action references when exiting PlayMode since those objects are no longer valid. + /// + internal static void ResetCachedAction() + { + var allActionRefs = Resources.FindObjectsOfTypeAll(typeof(InputActionReference)); + foreach (InputActionReference obj in allActionRefs) + { + obj.m_Action = null; + } + } + [SerializeField] internal InputActionAsset m_Asset; // Can't serialize System.Guid and Unity's GUID is editor only so these // go out as strings. diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs index c931232931..95314187fb 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs @@ -4491,23 +4491,27 @@ internal static void DeferredResolutionOfBindings() ++InputActionMap.s_DeferBindingResolution; try { - for (var i = 0; i < s_GlobalState.globalList.length; ++i) + if (InputActionMap.s_NeedToResolveBindings) { - var handle = s_GlobalState.globalList[i]; - - var state = handle.IsAllocated ? (InputActionState)handle.Target : null; - if (state == null) + for (var i = 0; i < s_GlobalState.globalList.length; ++i) { - // Stale entry in the list. State has already been reclaimed by GC. Remove it. - if (handle.IsAllocated) - s_GlobalState.globalList[i].Free(); - s_GlobalState.globalList.RemoveAtWithCapacity(i); - --i; - continue; - } + var handle = s_GlobalState.globalList[i]; - for (var n = 0; n < state.totalMapCount; ++n) - state.maps[n].ResolveBindingsIfNecessary(); + var state = handle.IsAllocated ? (InputActionState)handle.Target : null; + if (state == null) + { + // Stale entry in the list. State has already been reclaimed by GC. Remove it. + if (handle.IsAllocated) + s_GlobalState.globalList[i].Free(); + s_GlobalState.globalList.RemoveAtWithCapacity(i); + --i; + continue; + } + + for (var n = 0; n < state.totalMapCount; ++n) + state.maps[n].ResolveBindingsIfNecessary(); + } + InputActionMap.s_NeedToResolveBindings = false; } } finally diff --git a/Packages/com.unity.inputsystem/InputSystem/AssemblyInfo.cs b/Packages/com.unity.inputsystem/InputSystem/AssemblyInfo.cs index 3b19a617ac..2f32d3619e 100644 --- a/Packages/com.unity.inputsystem/InputSystem/AssemblyInfo.cs +++ b/Packages/com.unity.inputsystem/InputSystem/AssemblyInfo.cs @@ -16,7 +16,7 @@ public static partial class InputSystem // Keep this in sync with "Packages/com.unity.inputsystem/package.json". // NOTE: Unfortunately, System.Version doesn't use semantic versioning so we can't include // "-preview" suffixes here. - internal const string kAssemblyVersion = "1.8.3"; - internal const string kDocUrl = "https://docs.unity3d.com/Packages/com.unity.inputsystem@1.8"; + internal const string kAssemblyVersion = "1.9.0"; + internal const string kDocUrl = "https://docs.unity3d.com/Packages/com.unity.inputsystem@1.9"; } } diff --git a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControl.cs b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControl.cs index a9500197b6..38a6f16b0b 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControl.cs @@ -929,7 +929,7 @@ public void ApplyParameterChanges() private void SetOptimizedControlDataType() { // setting check need to be inline so we clear optimizations if setting is disabled after the fact - m_OptimizedControlDataType = InputSettings.optimizedControlsFeatureEnabled + m_OptimizedControlDataType = InputSystem.s_Manager.optimizedControlsFeatureEnabled ? CalculateOptimizedControlDataType() : (FourCC)InputStateBlock.kFormatInvalid; } @@ -957,7 +957,7 @@ internal void SetOptimizedControlDataTypeRecursively() [Conditional("UNITY_EDITOR")] internal void EnsureOptimizationTypeHasNotChanged() { - if (!InputSettings.optimizedControlsFeatureEnabled) + if (!InputSystem.s_Manager.optimizedControlsFeatureEnabled) return; var currentOptimizedControlDataType = CalculateOptimizedControlDataType(); @@ -1172,7 +1172,7 @@ public ref readonly TValue value if ( // if feature is disabled we re-evaluate every call - !InputSettings.readValueCachingFeatureEnabled + !InputSystem.s_Manager.readValueCachingFeatureEnabled // if cached value is stale we re-evaluate and clear the flag || m_CachedValueIsStale // if a processor in stack needs to be re-evaluated, but unprocessedValue is still can be cached @@ -1183,7 +1183,7 @@ public ref readonly TValue value m_CachedValueIsStale = false; } #if DEBUG - else if (InputSettings.paranoidReadValueCachingChecksEnabled) + else if (InputSystem.s_Manager.paranoidReadValueCachingChecksEnabled) { var oldUnprocessedValue = m_UnprocessedCachedValue; var newUnprocessedValue = unprocessedValue; @@ -1225,7 +1225,7 @@ internal unsafe ref readonly TValue unprocessedValue if ( // if feature is disabled we re-evaluate every call - !InputSettings.readValueCachingFeatureEnabled + !InputSystem.s_Manager.readValueCachingFeatureEnabled // if cached value is stale we re-evaluate and clear the flag || m_UnprocessedCachedValueIsStale ) @@ -1234,7 +1234,7 @@ internal unsafe ref readonly TValue unprocessedValue m_UnprocessedCachedValueIsStale = false; } #if DEBUG - else if (InputSettings.paranoidReadValueCachingChecksEnabled) + else if (InputSystem.s_Manager.paranoidReadValueCachingChecksEnabled) { var currentUnprocessedValue = ReadUnprocessedValueFromState(currentStatePtr); if (CompareValue(ref currentUnprocessedValue, ref m_UnprocessedCachedValue)) diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Commands/UseWindowsGamingInputCommand.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/Commands/UseWindowsGamingInputCommand.cs deleted file mode 100644 index d4eb6c7ad1..0000000000 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Commands/UseWindowsGamingInputCommand.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Runtime.InteropServices; -using UnityEngine.InputSystem.Utilities; - -namespace UnityEngine.InputSystem.LowLevel -{ - /// - // Command to enable or disable Windows.Gaming.Input native backend. - // Send it to deviceId 0 as it's a special "global" IOCTL that gets routed internally. - /// - [StructLayout(LayoutKind.Explicit, Size = kSize)] - internal struct UseWindowsGamingInputCommand : IInputDeviceCommandInfo - { - public static FourCC Type { get { return new FourCC('U', 'W', 'G', 'I'); } } - - internal const int kSize = InputDeviceCommand.kBaseCommandSize + sizeof(byte); - - [FieldOffset(0)] - public InputDeviceCommand baseCommand; - - [FieldOffset(InputDeviceCommand.kBaseCommandSize)] - public byte enable; - - public FourCC typeStatic - { - get { return Type; } - } - - public static UseWindowsGamingInputCommand Create(bool enable) - { - return new UseWindowsGamingInputCommand - { - baseCommand = new InputDeviceCommand(Type, kSize), - enable = (byte)(enable ? 1 : 0) - }; - } - } -} diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Commands/UseWindowsGamingInputCommand.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Devices/Commands/UseWindowsGamingInputCommand.cs.meta deleted file mode 100644 index a3299fcc27..0000000000 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Commands/UseWindowsGamingInputCommand.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f03e7044c375b7046b274ba59c850b2a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastKeyboard.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastKeyboard.cs index 26ab3fd7fd..f1f9a7fc83 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastKeyboard.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastKeyboard.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was auto-generated by com.unity.inputsystem:InputLayoutCodeGenerator -// version 1.8.3 +// version 1.9.0 // from "Keyboard" layout // // Changes to this file may cause incorrect behavior and will be lost if diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastMouse.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastMouse.cs index 006739c600..b57decd6d0 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastMouse.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastMouse.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was auto-generated by com.unity.inputsystem:InputLayoutCodeGenerator -// version 1.8.3 +// version 1.9.0 // from "Mouse" layout // // Changes to this file may cause incorrect behavior and will be lost if diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastTouchscreen.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastTouchscreen.cs index 16e6685b91..02a692edd5 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastTouchscreen.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastTouchscreen.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was auto-generated by com.unity.inputsystem:InputLayoutCodeGenerator -// version 1.8.3 +// version 1.9.0 // from "Touchscreen" layout // // Changes to this file may cause incorrect behavior and will be lost if diff --git a/Packages/com.unity.inputsystem/InputSystem/InputFeatureNames.cs b/Packages/com.unity.inputsystem/InputSystem/InputFeatureNames.cs index 5b9c9cea99..dae497bbe1 100644 --- a/Packages/com.unity.inputsystem/InputSystem/InputFeatureNames.cs +++ b/Packages/com.unity.inputsystem/InputSystem/InputFeatureNames.cs @@ -4,7 +4,6 @@ internal static class InputFeatureNames { public const string kRunPlayerUpdatesInEditMode = "RUN_PLAYER_UPDATES_IN_EDIT_MODE"; public const string kDisableUnityRemoteSupport = "DISABLE_UNITY_REMOTE_SUPPORT"; - public const string kUseWindowsGamingInputBackend = "USE_WINDOWS_GAMING_INPUT_BACKEND"; public const string kUseOptimizedControls = "USE_OPTIMIZED_CONTROLS"; public const string kUseReadValueCaching = "USE_READ_VALUE_CACHING"; public const string kParanoidReadValueCachingChecks = "PARANOID_READ_VALUE_CACHING_CHECKS"; diff --git a/Packages/com.unity.inputsystem/InputSystem/InputManager.cs b/Packages/com.unity.inputsystem/InputSystem/InputManager.cs index 5bee4ac31a..02dc53bd18 100644 --- a/Packages/com.unity.inputsystem/InputSystem/InputManager.cs +++ b/Packages/com.unity.inputsystem/InputSystem/InputManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using Unity.Collections; using UnityEngine.InputSystem.Composites; @@ -2116,6 +2117,33 @@ internal struct AvailableDevice internal IInputRuntime m_Runtime; internal InputMetrics m_Metrics; internal InputSettings m_Settings; + + // Extract as booleans (from m_Settings) because feature check is in the hot path + + private bool m_OptimizedControlsFeatureEnabled; + internal bool optimizedControlsFeatureEnabled + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => m_OptimizedControlsFeatureEnabled; + set => m_OptimizedControlsFeatureEnabled = value; + } + + private bool m_ReadValueCachingFeatureEnabled; + internal bool readValueCachingFeatureEnabled + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => m_ReadValueCachingFeatureEnabled; + set => m_ReadValueCachingFeatureEnabled = value; + } + + private bool m_ParanoidReadValueCachingChecksEnabled; + internal bool paranoidReadValueCachingChecksEnabled + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => m_ParanoidReadValueCachingChecksEnabled; + set => m_ParanoidReadValueCachingChecksEnabled = value; + } + #if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS private InputActionAsset m_Actions; #endif @@ -2645,12 +2673,10 @@ internal void ApplySettings() runPlayerUpdatesInEditMode = m_Settings.IsFeatureEnabled(InputFeatureNames.kRunPlayerUpdatesInEditMode); #endif - if (m_Settings.IsFeatureEnabled(InputFeatureNames.kUseWindowsGamingInputBackend)) - { - var command = UseWindowsGamingInputCommand.Create(true); - if (ExecuteGlobalCommand(ref command) < 0) - Debug.LogError($"Could not enable Windows.Gaming.Input"); - } + // Extract feature flags into fields since used in hot-path + m_ReadValueCachingFeatureEnabled = m_Settings.IsFeatureEnabled((InputFeatureNames.kUseReadValueCaching)); + m_OptimizedControlsFeatureEnabled = m_Settings.IsFeatureEnabled((InputFeatureNames.kUseOptimizedControls)); + m_ParanoidReadValueCachingChecksEnabled = m_Settings.IsFeatureEnabled((InputFeatureNames.kParanoidReadValueCachingChecks)); } // Cache some values. @@ -3549,7 +3575,7 @@ private void ResetCurrentProcessedEventBytesForDevices() [Conditional("UNITY_EDITOR")] void CheckAllDevicesOptimizedControlsHaveValidState() { - if (!InputSettings.optimizedControlsFeatureEnabled) + if (!InputSystem.s_Manager.m_OptimizedControlsFeatureEnabled) return; foreach (var device in devices) @@ -3739,7 +3765,7 @@ private unsafe void WriteStateChange(InputStateBuffers.DoubleBuffers buffers, in deviceStateSize); } - if (InputSettings.readValueCachingFeatureEnabled) + if (InputSystem.s_Manager.m_ReadValueCachingFeatureEnabled) { // if the buffers have just been flipped, and we're doing a full state update, then the state from the // previous update is now in the back buffer, and we should be comparing to that when checking what diff --git a/Packages/com.unity.inputsystem/InputSystem/InputSettings.cs b/Packages/com.unity.inputsystem/InputSystem/InputSettings.cs index c9cdafa369..e79bd68402 100644 --- a/Packages/com.unity.inputsystem/InputSystem/InputSettings.cs +++ b/Packages/com.unity.inputsystem/InputSystem/InputSettings.cs @@ -717,27 +717,13 @@ public void SetInternalFeatureFlag(string featureName, bool enabled) if (string.IsNullOrEmpty(featureName)) throw new ArgumentNullException(nameof(featureName)); - switch (featureName) - { - case InputFeatureNames.kUseOptimizedControls: - optimizedControlsFeatureEnabled = enabled; - break; - case InputFeatureNames.kUseReadValueCaching: - readValueCachingFeatureEnabled = enabled; - break; - case InputFeatureNames.kParanoidReadValueCachingChecks: - paranoidReadValueCachingChecksEnabled = enabled; - break; - default: - if (m_FeatureFlags == null) - m_FeatureFlags = new HashSet(); - - if (enabled) - m_FeatureFlags.Add(featureName.ToUpperInvariant()); - else - m_FeatureFlags.Remove(featureName.ToUpperInvariant()); - break; - } + if (m_FeatureFlags == null) + m_FeatureFlags = new HashSet(); + + if (enabled) + m_FeatureFlags.Add(featureName.ToUpperInvariant()); + else + m_FeatureFlags.Remove(featureName.ToUpperInvariant()); OnChange(); } @@ -778,11 +764,6 @@ internal bool IsFeatureEnabled(string featureName) return m_FeatureFlags != null && m_FeatureFlags.Contains(featureName.ToUpperInvariant()); } - // Needs a static field because feature check is in the hot path - internal static bool optimizedControlsFeatureEnabled = false; - internal static bool readValueCachingFeatureEnabled; - internal static bool paranoidReadValueCachingChecksEnabled; - internal void OnChange() { if (InputSystem.settings == this) diff --git a/Packages/com.unity.inputsystem/InputSystem/InputSystem.cs b/Packages/com.unity.inputsystem/InputSystem/InputSystem.cs index c7f78b18bd..baf095b79c 100644 --- a/Packages/com.unity.inputsystem/InputSystem/InputSystem.cs +++ b/Packages/com.unity.inputsystem/InputSystem/InputSystem.cs @@ -3662,6 +3662,9 @@ internal static void OnPlayModeChange(PlayModeStateChange change) // Nuke all InputActionMapStates. Releases their unmanaged memory. InputActionState.DestroyAllActionMapStates(); + // Clear the Action reference from all InputActionReference objects + InputActionReference.ResetCachedAction(); + // Restore settings. if (!string.IsNullOrEmpty(s_SystemObject.settings)) { diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockGamepadHID.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockGamepadHID.cs index ca4ff95ea4..3cb6a963ef 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockGamepadHID.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockGamepadHID.cs @@ -17,7 +17,7 @@ namespace UnityEngine.InputSystem.DualShock.LowLevel /// See ConvertInputReport for the exact conversion. /// [StructLayout(LayoutKind.Explicit, Size = 9 /* !!! Beware !!! If you plan to increase this, think about how you gonna fit 10 byte state events because we can only shrink events in IEventPreProcessor */)] - internal struct DualSenseHIDInputReport : IInputStateTypeInfo + public struct DualSenseHIDInputReport : IInputStateTypeInfo { public static FourCC Format = new FourCC('D', 'S', 'V', 'S'); // DualSense Virtual State public FourCC format => Format; @@ -349,7 +349,7 @@ public class DualSenseGamepadHID : DualShockGamepad, IEventMerger, IEventPreProc private float? m_LowFrequencyMotorSpeed; private float? m_HighFrequenceyMotorSpeed; - private Color? m_LightBarColor; + protected Color? m_LightBarColor; private byte outputSequenceId; protected override void FinishSetup() diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenButton.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenButton.cs index e20bbf7256..1afd7125eb 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenButton.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenButton.cs @@ -1,5 +1,4 @@ #if PACKAGE_DOCS_GENERATION || UNITY_INPUT_SYSTEM_ENABLE_UI -using System; using UnityEngine.EventSystems; using UnityEngine.InputSystem.Layouts; @@ -45,6 +44,29 @@ protected override string controlPathInternal get => m_ControlPath; set => m_ControlPath = value; } + +#if UNITY_EDITOR + [UnityEditor.CustomEditor(typeof(OnScreenButton))] + internal class OnScreenButtonEditor : UnityEditor.Editor + { + private UnityEditor.SerializedProperty m_ControlPathInternal; + + public void OnEnable() + { + m_ControlPathInternal = serializedObject.FindProperty(nameof(OnScreenButton.m_ControlPath)); + } + + public override void OnInspectorGUI() + { + // Current implementation has UGUI dependencies (ISXB-915, ISXB-916) + UGUIOnScreenControlEditorUtils.ShowWarningIfNotPartOfCanvasHierarchy((OnScreenButton)target); + + UnityEditor.EditorGUILayout.PropertyField(m_ControlPathInternal); + + serializedObject.ApplyModifiedProperties(); + } + } +#endif } } #endif diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenControl.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenControl.cs index 85f9756ef1..d1fedda694 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenControl.cs @@ -299,5 +299,30 @@ public void Destroy() } private static InlinedArray s_OnScreenDevices; + + internal string GetWarningMessage() + { + return $"{GetType()} needs to be attached as a child to a UI Canvas and have a RectTransform component to function properly."; + } + } + + internal static class UGUIOnScreenControlUtils + { + public static RectTransform GetCanvasRectTransform(Transform transform) + { + var parentTransform = transform.parent; + return parentTransform != null ? transform.parent.GetComponentInParent() : null; + } + } + +#if UNITY_EDITOR + internal static class UGUIOnScreenControlEditorUtils + { + public static void ShowWarningIfNotPartOfCanvasHierarchy(OnScreenControl target) + { + if (UGUIOnScreenControlUtils.GetCanvasRectTransform(target.transform) == null) + UnityEditor.EditorGUILayout.HelpBox(target.GetWarningMessage(), UnityEditor.MessageType.Warning); + } } +#endif } diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenStick.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenStick.cs index 978931a15a..0e5bae8514 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenStick.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenStick.cs @@ -112,9 +112,14 @@ private void Start() m_PointerMoveAction.Enable(); } + // Unable to setup elements according to settings if a RectTransform is not available (ISXB-915, ISXB-916). + if (!(transform is RectTransform)) + return; + m_StartPos = ((RectTransform)transform).anchoredPosition; if (m_Behaviour != Behaviour.ExactPositionWithDynamicOrigin) return; + m_PointerDownPos = m_StartPos; var dynamicOrigin = new GameObject(kDynamicOriginClickable, typeof(Image)); @@ -132,24 +137,24 @@ private void Start() private void BeginInteraction(Vector2 pointerPosition, Camera uiCamera) { - var canvasRect = transform.parent?.GetComponentInParent(); - if (canvasRect == null) + var canvasRectTransform = UGUIOnScreenControlUtils.GetCanvasRectTransform(transform); + if (canvasRectTransform == null) { - Debug.LogError("OnScreenStick needs to be attached as a child to a UI Canvas to function properly."); + Debug.LogError(GetWarningMessage()); return; } switch (m_Behaviour) { case Behaviour.RelativePositionWithStaticOrigin: - RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, pointerPosition, uiCamera, out m_PointerDownPos); + RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, pointerPosition, uiCamera, out m_PointerDownPos); break; case Behaviour.ExactPositionWithStaticOrigin: - RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, pointerPosition, uiCamera, out m_PointerDownPos); + RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, pointerPosition, uiCamera, out m_PointerDownPos); MoveStick(pointerPosition, uiCamera); break; case Behaviour.ExactPositionWithDynamicOrigin: - RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, pointerPosition, uiCamera, out var pointerDown); + RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, pointerPosition, uiCamera, out var pointerDown); m_PointerDownPos = ((RectTransform)transform).anchoredPosition = pointerDown; break; } @@ -157,13 +162,14 @@ private void BeginInteraction(Vector2 pointerPosition, Camera uiCamera) private void MoveStick(Vector2 pointerPosition, Camera uiCamera) { - var canvasRect = transform.parent?.GetComponentInParent(); - if (canvasRect == null) + var canvasRectTransform = UGUIOnScreenControlUtils.GetCanvasRectTransform(transform); + if (canvasRectTransform == null) { - Debug.LogError("OnScreenStick needs to be attached as a child to a UI Canvas to function properly."); + Debug.LogError(GetWarningMessage()); return; } - RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, pointerPosition, uiCamera, out var position); + + RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, pointerPosition, uiCamera, out var position); var delta = position - m_PointerDownPos; switch (m_Behaviour) @@ -253,9 +259,14 @@ private Camera GetCameraFromCanvas() private void OnDrawGizmosSelected() { - Gizmos.matrix = ((RectTransform)transform.parent).localToWorldMatrix; + // This will not produce meaningful results unless we have a rect transform (ISXB-915, ISXB-916). + var parentRectTransform = transform.parent as RectTransform; + if (parentRectTransform == null) + return; + + Gizmos.matrix = parentRectTransform.localToWorldMatrix; - var startPos = ((RectTransform)transform).anchoredPosition; + var startPos = parentRectTransform.anchoredPosition; if (Application.isPlaying) startPos = m_StartPos; @@ -457,6 +468,9 @@ public void OnEnable() public override void OnInspectorGUI() { + // Current implementation has UGUI dependencies (ISXB-915, ISXB-916) + UGUIOnScreenControlEditorUtils.ShowWarningIfNotPartOfCanvasHierarchy((OnScreenStick)target); + EditorGUILayout.PropertyField(m_MovementRange); EditorGUILayout.PropertyField(m_ControlPathInternal); EditorGUILayout.PropertyField(m_Behaviour); diff --git a/Packages/com.unity.inputsystem/Tests/TestFixture/AssemblyInfo.cs b/Packages/com.unity.inputsystem/Tests/TestFixture/AssemblyInfo.cs index c9631526b1..e13c47f98e 100644 --- a/Packages/com.unity.inputsystem/Tests/TestFixture/AssemblyInfo.cs +++ b/Packages/com.unity.inputsystem/Tests/TestFixture/AssemblyInfo.cs @@ -4,7 +4,7 @@ // Keep this in sync with "Packages/com.unity.inputsystem/package.json". // NOTE: Unfortunately, System.Version doesn't use semantic versioning so we can't include // "-preview" suffixes here. -[assembly: AssemblyVersion("1.8.3")] +[assembly: AssemblyVersion("1.9.0")] [assembly: InternalsVisibleTo("Unity.InputSystem.Tests.Editor")] [assembly: InternalsVisibleTo("Unity.InputSystem.Tests")] [assembly: InternalsVisibleTo("Unity.InputSystem.IntegrationTests")] diff --git a/Packages/com.unity.inputsystem/package.json b/Packages/com.unity.inputsystem/package.json index 4129c803a7..7c25c5e5a8 100755 --- a/Packages/com.unity.inputsystem/package.json +++ b/Packages/com.unity.inputsystem/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.inputsystem", "displayName": "Input System", - "version": "1.8.3", + "version": "1.9.0", "unity": "2019.4", "description": "A new input system which can be used as a more extensible and customizable alternative to Unity's classic input system in UnityEngine.Input.", "keywords": [