@@ -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