-
Notifications
You must be signed in to change notification settings - Fork 333
FIX: Avoid disabling project-wide actions on shutdown #2346
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
base: develop
Are you sure you want to change the base?
Changes from 4 commits
c562118
0ed73d8
e917c04
61807cc
b087ccd
9cdf098
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ public class InputForUITests : InputTestFixture | |
| readonly List<Event> m_InputForUIEvents = new List<Event>(); | ||
| private int m_CurrentInputEventToCheck; | ||
| InputSystemProvider m_InputSystemProvider; | ||
| private bool m_ClearedMockProvider; | ||
|
|
||
| private InputActionAsset storedActions; | ||
|
|
||
|
|
@@ -45,6 +46,7 @@ public override void Setup() | |
| { | ||
| base.Setup(); | ||
| m_CurrentInputEventToCheck = 0; | ||
| m_ClearedMockProvider = false; | ||
|
|
||
| storedActions = InputSystem.actions; | ||
|
|
||
|
|
@@ -59,7 +61,8 @@ public override void Setup() | |
| public override void TearDown() | ||
| { | ||
| EventProvider.Unsubscribe(InputForUIOnEvent); | ||
| EventProvider.ClearMockProvider(); | ||
| if (!m_ClearedMockProvider) | ||
| EventProvider.ClearMockProvider(); | ||
| m_InputForUIEvents.Clear(); | ||
|
|
||
| InputSystem.s_Manager.actions = storedActions; | ||
|
|
@@ -92,6 +95,34 @@ public void InputSystemActionAssetIsNotNull() | |
| "Test is invalid since InputSystemProvider actions are not available"); | ||
| } | ||
|
|
||
| [Test] | ||
| [Category(kTestCategory)] | ||
| public void Shutdown_DoesNotDisableProjectWideActionsAsset() | ||
| { | ||
| var asset = ScriptableObject.CreateInstance<InputActionAsset>(); | ||
| var uiMap = new InputActionMap("UI"); | ||
| uiMap.AddAction("Point", InputActionType.PassThrough, "<Mouse>/position"); | ||
| uiMap.AddAction("Navigate", InputActionType.PassThrough, "<Gamepad>/leftStick"); | ||
| uiMap.AddAction("Submit", InputActionType.Button, "<Keyboard>/enter"); | ||
| uiMap.AddAction("Cancel", InputActionType.Button, "<Keyboard>/escape"); | ||
| uiMap.AddAction("Click", InputActionType.PassThrough, "<Mouse>/leftButton"); | ||
| uiMap.AddAction("MiddleClick", InputActionType.PassThrough, "<Mouse>/middleButton"); | ||
| uiMap.AddAction("RightClick", InputActionType.PassThrough, "<Mouse>/rightButton"); | ||
| uiMap.AddAction("ScrollWheel", InputActionType.PassThrough, "<Mouse>/scroll"); | ||
| asset.AddActionMap(uiMap); | ||
|
|
||
| InputSystem.s_Manager.actions = asset; | ||
|
|
||
| m_InputSystemProvider.Initialize(); | ||
| Assert.That(asset.enabled, Is.True, "Project-wide actions should be enabled by provider initialization."); | ||
|
|
||
| EventProvider.ClearMockProvider(); | ||
| m_ClearedMockProvider = true; | ||
| Assert.That(asset.enabled, Is.True, "Project-wide actions must remain enabled after provider shutdown."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the provider was responsible for enabling the "UI" map (which it will be here since the asset is newly created and its maps are disabled by default), it will disable that map during shutdown. Since no other maps are enabled in this test asset, 🤖 Helpful? 👍/👎 |
||
|
|
||
| Object.DestroyImmediate(asset); | ||
| } | ||
|
|
||
| [Test] | ||
| [Category(kTestCategory)] | ||
| // Checks that mouse events are ignored when a touch is active. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -664,7 +664,7 @@ void UnregisterActions() | |
| UnregisterAction(ref m_RightClickAction, OnRightClickPerformed); | ||
| UnregisterAction(ref m_ScrollWheelAction, OnScrollWheelPerformed); | ||
|
|
||
| if (m_InputActionAsset != null) | ||
| if (m_InputActionAsset != null && m_InputActionAsset != InputSystem.actions) | ||
|
||
| m_InputActionAsset.Disable(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better maintainability and consistency with the rest of the test class, consider using the public
InputSystem.actionsproperty instead of the internals_Managerfield. This aligns with the access pattern used in theSetupmethod.🤖 Helpful? 👍/👎