@@ -20,34 +20,26 @@ public class ScrollWithInput : MonoBehaviour
2020 /// </summary>
2121 public ScrollRect scrollRect { get ; private set ; }
2222
23- /// <summary>
24- /// The direction to scroll the ScrollRect.
25- /// </summary>
26- [ Tooltip ( "The direction to scroll the ScrollRect." ) ]
27- public ScrollDirection scrollDirection = ScrollDirection . Vertical ;
28-
2923 #if ENABLE_INPUT_SYSTEM
30-
3124 /// <summary>
3225 /// The input action that handles scrolling.
3326 /// </summary>
3427 [ Tooltip ( "The input action that handles scrolling." ) ]
3528 public InputAction scrollInput = new InputAction ( "ScrollInput" , InputActionType . Value , null , null , null , "Vector2" ) ;
29+ #endif
3630
37- #elif ENABLE_LEGACY_INPUT_MANAGER
38-
31+ #if ENABLE_LEGACY_INPUT_MANAGER
3932 /// <summary>
40- /// The input axis that handles scrolling in the y-axis.
33+ /// The legacy input axis that handles scrolling in the y-axis.
4134 /// </summary>
42- [ Tooltip ( "The input axis that handles scrolling in the y-axis." ) ]
43- public string scrollInputAxisY = "" ;
35+ [ Tooltip ( "The legacy input axis that handles scrolling in the y-axis." ) ]
36+ public string legacyScrollInputY = "" ;
4437
4538 /// <summary>
46- /// The input axis that handles scrolling in the x-axis.
39+ /// The legacy input axis that handles scrolling in the x-axis.
4740 /// </summary>
48- [ Tooltip ( "The input axis that handles scrolling in the x-axis." ) ]
49- public string scrollInputAxisX = "" ;
50-
41+ [ Tooltip ( "The legacy input axis that handles scrolling in the x-axis." ) ]
42+ public string legacyScrollInputX = "" ;
5143 #endif
5244
5345 /// <summary>
@@ -56,6 +48,12 @@ public class ScrollWithInput : MonoBehaviour
5648 [ Tooltip ( "The sensitivity multiplier applied to the input." ) ]
5749 public float sensitivity = 1f ;
5850
51+ /// <summary>
52+ /// The direction to scroll the ScrollRect.
53+ /// </summary>
54+ [ Tooltip ( "The direction to scroll the ScrollRect." ) ]
55+ public ScrollDirection direction = ScrollDirection . Vertical ;
56+
5957 private void Awake ( )
6058 {
6159 scrollRect = GetComponent < ScrollRect > ( ) ;
@@ -96,17 +94,19 @@ private void Update()
9694
9795 #if ENABLE_INPUT_SYSTEM
9896 input = scrollInput . ReadValue < Vector2 > ( ) ;
99- #elif ENABLE_LEGACY_INPUT_MANAGER
100- if ( scrollInputAxisY != "" ) {
101- input . y = Input . GetAxis ( scrollInputAxisY ) ;
97+ #endif
98+
99+ #if ENABLE_LEGACY_INPUT_MANAGER
100+ if ( input . y == 0f ) {
101+ input . y = GetAxis ( legacyScrollInputX ) ;
102102 }
103103
104- if ( scrollInputAxisX != "" ) {
105- input . x = Input . GetAxis ( scrollInputAxisX ) ;
104+ if ( input . x == 0f ) {
105+ input . x = GetAxis ( legacyScrollInputY ) ;
106106 }
107107 #endif
108108
109- switch ( scrollDirection )
109+ switch ( direction )
110110 {
111111 case ScrollDirection . Vertical :
112112 input . x = 0f ;
@@ -121,6 +121,28 @@ private void Update()
121121 }
122122 }
123123
124+ #if ENABLE_LEGACY_INPUT_MANAGER
125+ private float GetAxis ( string inputName )
126+ {
127+ float value = 0f ;
128+
129+ try
130+ {
131+ if ( ! string . IsNullOrEmpty ( inputName ) ) {
132+ value = Input . GetAxis ( inputName ) ;
133+ }
134+ }
135+ catch
136+ {
137+ #if UNITY_EDITOR || DEVELOPMENT_BUILD
138+ Debug . LogWarning ( $ "[ScrollWithInput]: Input axis '{ inputName } ' is not setup.\n Define the input in the Input Manager settings accessed from the menu: Edit > Project Settings") ;
139+ #endif
140+ }
141+
142+ return value ;
143+ }
144+ #endif
145+
124146 }
125147
126148}
0 commit comments