@@ -13,10 +13,9 @@ namespace UnityEngine.InputSystem.Plugins.InputForUI
13
13
14
14
internal class InputSystemProvider : IEventProviderImpl
15
15
{
16
- Configuration m_Cfg ;
17
-
18
16
InputEventPartialProvider m_InputEventPartialProvider ;
19
17
18
+ DefaultInputActions m_DefaultInputActions ;
20
19
InputActionAsset m_InputActionAsset ;
21
20
22
21
InputActionReference m_PointAction ;
@@ -86,28 +85,37 @@ public void Initialize()
86
85
m_TouchState . Reset ( ) ;
87
86
m_SeenTouchEvents = false ;
88
87
89
- m_Cfg = Configuration . GetDefaultConfiguration ( ) ;
90
-
88
+ SelectInputActionAsset ( ) ;
91
89
RegisterActions ( ) ;
92
90
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
+
93
95
InputSystem . onActionsChange += OnActionsChange ;
94
96
}
95
97
96
98
public void Shutdown ( )
97
99
{
98
100
UnregisterActions ( ) ;
101
+ UnregisterFixedActions ( ) ;
99
102
100
103
m_InputEventPartialProvider . Shutdown ( ) ;
101
104
m_InputEventPartialProvider = null ;
102
105
106
+ if ( m_DefaultInputActions != null )
107
+ {
108
+ m_DefaultInputActions . Dispose ( ) ;
109
+ m_DefaultInputActions = null ;
110
+ }
111
+
103
112
InputSystem . onActionsChange -= OnActionsChange ;
104
113
}
105
114
106
115
public void OnActionsChange ( )
107
116
{
108
117
UnregisterActions ( ) ;
109
-
110
- m_Cfg = Configuration . GetDefaultConfiguration ( ) ;
118
+ SelectInputActionAsset ( ) ;
111
119
RegisterActions ( ) ;
112
120
}
113
121
@@ -584,7 +592,7 @@ void OnScrollWheelPerformed(InputAction.CallbackContext ctx)
584
592
} ) ) ;
585
593
}
586
594
587
- void RegisterNextPreviousAction ( )
595
+ void RegisterFixedActions ( )
588
596
{
589
597
m_NextPreviousAction = new InputAction ( name : "nextPreviousAction" , type : InputActionType . Button ) ;
590
598
// TODO add more default bindings, or make them configurable
@@ -604,19 +612,17 @@ void UnregisterFixedActions()
604
612
605
613
void RegisterActions ( )
606
614
{
607
- m_InputActionAsset = m_Cfg . ActionAsset ;
608
-
609
615
// Invoke potential lister observing registration
610
616
s_OnRegisterActions ? . Invoke ( m_InputActionAsset ) ;
611
617
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 ) ) ;
620
626
621
627
if ( m_PointAction != null && m_PointAction . action != null )
622
628
m_PointAction . action . performed += OnPointerPerformed ;
@@ -648,10 +654,6 @@ void RegisterActions()
648
654
}
649
655
else
650
656
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 ( ) ;
655
657
}
656
658
657
659
void UnregisterActions ( )
@@ -688,49 +690,43 @@ void UnregisterActions()
688
690
689
691
if ( m_InputActionAsset != null )
690
692
m_InputActionAsset . Disable ( ) ;
691
-
692
- UnregisterFixedActions ( ) ;
693
693
}
694
694
695
- public struct Configuration
695
+ void SelectInputActionAsset ( )
696
696
{
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 ;
706
704
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
708
710
{
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 ;
731
715
}
732
716
}
733
717
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
+
734
730
internal static void SetOnRegisterActions ( Action < InputActionAsset > callback )
735
731
{
736
732
s_OnRegisterActions = callback ;
0 commit comments