Skip to content

Commit 48f1a02

Browse files
committed
Moved 'InputActionAsset' out of InputSystemProvider.Configuration, made the action strings readonly and renamed the class 'Actions', Added reused DefaultInputActions field to InputSystemProvider and added new 'SelectInputActionAsset' method to select the input asset used (either project wide asset or default input actions), Renamed 'RegisterNextPreviousAction' to 'RegisterFixedActions' to better mirror method used to unregister these actions - moved these methods to be called in Initialize / Shutdown to avoid re-registering when not required, Simplified InputActionAssetVerifier.Verify now that configuration action strings are statically known (an instance of the struct is no longer required)
1 parent 95ab1a9 commit 48f1a02

File tree

2 files changed

+69
-81
lines changed

2 files changed

+69
-81
lines changed

Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputActionAssetVerifier.cs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,23 @@ static InputActionAssetVerifier()
3232
public void Verify(InputActionAsset asset,
3333
ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors reporter)
3434
{
35-
// Note that we never cache this to guarantee we have the current configuration.
36-
var config = InputSystemProvider.Configuration.GetDefaultConfiguration();
37-
Verify(asset, ref config, reporter);
35+
// Note:
36+
// PWA has initial state check true for "Point" action, DefaultActions do not, does it matter?
37+
//
38+
// Additionally note that "Submit" and "Cancel" are indirectly expected to be of Button action type.
39+
// This is not available in UI configuration, but InputActionRebindingExtensions suggests this.
40+
//
41+
// Additional "LeftClick" has initial state check set in PWA, but not "MiddleClick" and "RightClick".
42+
// Is this intentional? Are requirements different?
43+
var context = new Context(asset, reporter, DefaultReportPolicy);
44+
context.Verify(actionNameOrId: InputSystemProvider.Actions.PointAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
45+
context.Verify(actionNameOrId: InputSystemProvider.Actions.MoveAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
46+
context.Verify(actionNameOrId: InputSystemProvider.Actions.SubmitAction, actionType: InputActionType.Button, expectedControlType: "Button");
47+
context.Verify(actionNameOrId: InputSystemProvider.Actions.CancelAction, actionType: InputActionType.Button, expectedControlType: "Button");
48+
context.Verify(actionNameOrId: InputSystemProvider.Actions.LeftClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
49+
context.Verify(actionNameOrId: InputSystemProvider.Actions.MiddleClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
50+
context.Verify(actionNameOrId: InputSystemProvider.Actions.RightClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
51+
context.Verify(actionNameOrId: InputSystemProvider.Actions.ScrollWheelAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
3852
}
3953

4054
#endregion
@@ -111,28 +125,6 @@ public void Verify(string actionNameOrId, InputActionType actionType, string exp
111125
private HashSet<string> missingPaths; // Avoids generating multiple warnings around missing map
112126
private ReportPolicy policy;
113127
}
114-
115-
private static void Verify(InputActionAsset asset, ref InputSystemProvider.Configuration config,
116-
ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors reporter)
117-
{
118-
// Note:
119-
// PWA has initial state check true for "Point" action, DefaultActions do not, does it matter?
120-
//
121-
// Additionally note that "Submit" and "Cancel" are indirectly expected to be of Button action type.
122-
// This is not available in UI configuration, but InputActionRebindingExtensions suggests this.
123-
//
124-
// Additional "LeftClick" has initial state check set in PWA, but not "MiddleClick" and "RightClick".
125-
// Is this intentional? Are requirements different?
126-
var context = new Context(asset, reporter, DefaultReportPolicy);
127-
context.Verify(actionNameOrId: config.PointAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
128-
context.Verify(actionNameOrId: config.MoveAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
129-
context.Verify(actionNameOrId: config.SubmitAction, actionType: InputActionType.Button, expectedControlType: "Button");
130-
context.Verify(actionNameOrId: config.CancelAction, actionType: InputActionType.Button, expectedControlType: "Button");
131-
context.Verify(actionNameOrId: config.LeftClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
132-
context.Verify(actionNameOrId: config.MiddleClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
133-
context.Verify(actionNameOrId: config.RightClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
134-
context.Verify(actionNameOrId: config.ScrollWheelAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
135-
}
136128
}
137129
}
138130

Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputSystemProvider.cs

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ namespace UnityEngine.InputSystem.Plugins.InputForUI
1313

1414
internal class InputSystemProvider : IEventProviderImpl
1515
{
16-
Configuration m_Cfg;
17-
1816
InputEventPartialProvider m_InputEventPartialProvider;
1917

18+
DefaultInputActions m_DefaultInputActions;
2019
InputActionAsset m_InputActionAsset;
2120

2221
InputActionReference m_PointAction;
@@ -86,28 +85,37 @@ public void Initialize()
8685
m_TouchState.Reset();
8786
m_SeenTouchEvents = false;
8887

89-
m_Cfg = Configuration.GetDefaultConfiguration();
90-
88+
SelectInputActionAsset();
9189
RegisterActions();
9290

91+
// TODO make it configurable as it is not part of default config
92+
// The Next/Previous action is not part of the input actions asset
93+
RegisterFixedActions();
94+
9395
InputSystem.onActionsChange += OnActionsChange;
9496
}
9597

9698
public void Shutdown()
9799
{
98100
UnregisterActions();
101+
UnregisterFixedActions();
99102

100103
m_InputEventPartialProvider.Shutdown();
101104
m_InputEventPartialProvider = null;
102105

106+
if (m_DefaultInputActions != null)
107+
{
108+
m_DefaultInputActions.Dispose();
109+
m_DefaultInputActions = null;
110+
}
111+
103112
InputSystem.onActionsChange -= OnActionsChange;
104113
}
105114

106115
public void OnActionsChange()
107116
{
108117
UnregisterActions();
109-
110-
m_Cfg = Configuration.GetDefaultConfiguration();
118+
SelectInputActionAsset();
111119
RegisterActions();
112120
}
113121

@@ -584,7 +592,7 @@ void OnScrollWheelPerformed(InputAction.CallbackContext ctx)
584592
}));
585593
}
586594

587-
void RegisterNextPreviousAction()
595+
void RegisterFixedActions()
588596
{
589597
m_NextPreviousAction = new InputAction(name: "nextPreviousAction", type: InputActionType.Button);
590598
// TODO add more default bindings, or make them configurable
@@ -604,19 +612,17 @@ void UnregisterFixedActions()
604612

605613
void RegisterActions()
606614
{
607-
m_InputActionAsset = m_Cfg.ActionAsset;
608-
609615
// Invoke potential lister observing registration
610616
s_OnRegisterActions?.Invoke(m_InputActionAsset);
611617

612-
m_PointAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.PointAction));
613-
m_MoveAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.MoveAction));
614-
m_SubmitAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.SubmitAction));
615-
m_CancelAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.CancelAction));
616-
m_LeftClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.LeftClickAction));
617-
m_MiddleClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.MiddleClickAction));
618-
m_RightClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.RightClickAction));
619-
m_ScrollWheelAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.ScrollWheelAction));
618+
m_PointAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.PointAction));
619+
m_MoveAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.MoveAction));
620+
m_SubmitAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.SubmitAction));
621+
m_CancelAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.CancelAction));
622+
m_LeftClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.LeftClickAction));
623+
m_MiddleClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.MiddleClickAction));
624+
m_RightClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.RightClickAction));
625+
m_ScrollWheelAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.ScrollWheelAction));
620626

621627
if (m_PointAction != null && m_PointAction.action != null)
622628
m_PointAction.action.performed += OnPointerPerformed;
@@ -648,10 +654,6 @@ void RegisterActions()
648654
}
649655
else
650656
m_InputActionAsset.Enable();
651-
652-
// TODO make it configurable as it is not part of default config
653-
// The Next/Previous action is not part of the input actions asset
654-
RegisterNextPreviousAction();
655657
}
656658

657659
void UnregisterActions()
@@ -688,49 +690,43 @@ void UnregisterActions()
688690

689691
if (m_InputActionAsset != null)
690692
m_InputActionAsset.Disable();
691-
692-
UnregisterFixedActions();
693693
}
694694

695-
public struct Configuration
695+
void SelectInputActionAsset()
696696
{
697-
public InputActionAsset ActionAsset;
698-
public string PointAction;
699-
public string MoveAction;
700-
public string SubmitAction;
701-
public string CancelAction;
702-
public string LeftClickAction;
703-
public string MiddleClickAction;
704-
public string RightClickAction;
705-
public string ScrollWheelAction;
697+
// Only use default actions asset configuration if (ISX-1954):
698+
// - Project-wide Input Actions have not been configured, OR
699+
// - Project-wide Input Actions have been configured but contains no UI action map.
700+
var projectWideInputActions = InputSystem.actions;
701+
var useProjectWideInputActions =
702+
projectWideInputActions != null &&
703+
projectWideInputActions.FindActionMap("UI") != null;
706704

707-
public static Configuration GetDefaultConfiguration()
705+
// Use InputSystem.actions (Project-wide Actions) if available, else use default asset if
706+
// user didn't specifically set one, so that UI functions still work (ISXB-811).
707+
if (useProjectWideInputActions)
708+
m_InputActionAsset = InputSystem.actions;
709+
else
708710
{
709-
// Only use default actions asset configuration if (ISX-1954):
710-
// - Project-wide Input Actions have not been configured, OR
711-
// - Project-wide Input Actions have been configured but contains no UI action map.
712-
var projectWideInputActions = InputSystem.actions;
713-
var useProjectWideInputActions =
714-
projectWideInputActions != null &&
715-
projectWideInputActions.FindActionMap("UI") != null;
716-
717-
// Use InputSystem.actions (Project-wide Actions) if available, else use default asset if
718-
// user didn't specifically set one, so that UI functions still work (ISXB-811).
719-
return new Configuration
720-
{
721-
ActionAsset = useProjectWideInputActions ? InputSystem.actions : new DefaultInputActions().asset,
722-
PointAction = "UI/Point",
723-
MoveAction = "UI/Navigate",
724-
SubmitAction = "UI/Submit",
725-
CancelAction = "UI/Cancel",
726-
LeftClickAction = "UI/Click",
727-
MiddleClickAction = "UI/MiddleClick",
728-
RightClickAction = "UI/RightClick",
729-
ScrollWheelAction = "UI/ScrollWheel",
730-
};
711+
if (m_DefaultInputActions is null)
712+
m_DefaultInputActions = new DefaultInputActions();
713+
714+
m_InputActionAsset = m_DefaultInputActions.asset;
731715
}
732716
}
733717

718+
public static class Actions
719+
{
720+
public readonly static string PointAction = "UI/Point";
721+
public readonly static string MoveAction = "UI/Navigate";
722+
public readonly static string SubmitAction = "UI/Submit";
723+
public readonly static string CancelAction = "UI/Cancel";
724+
public readonly static string LeftClickAction = "UI/Click";
725+
public readonly static string MiddleClickAction = "UI/MiddleClick";
726+
public readonly static string RightClickAction = "UI/RightClick";
727+
public readonly static string ScrollWheelAction = "UI/ScrollWheel";
728+
}
729+
734730
internal static void SetOnRegisterActions(Action<InputActionAsset> callback)
735731
{
736732
s_OnRegisterActions = callback;

0 commit comments

Comments
 (0)