@@ -195,8 +195,47 @@ public void UpdateControllers(UnityEngine.Object context, float deltaTime)
195195 c . Driver . ProcessInput ( ref m_Axes [ i ] . DrivenAxis ( ) , c . InputValue , deltaTime ) ;
196196 }
197197 }
198- }
199198
199+ int GetControllerIndex ( string axisName )
200+ {
201+ for ( int i = 0 ; i < Controllers . Count ; ++ i )
202+ {
203+ var c = Controllers [ i ] ;
204+ if ( c . Name == axisName )
205+ return i ;
206+ }
207+ return - 1 ;
208+ }
209+
210+ /// <summary>
211+ /// Get the controller for a given axis name. The axis name is the name displayed
212+ /// for the axis foldout on the inspector.
213+ /// </summary>
214+ /// <param name="axisName">The name of the axis, as it appears in the inspector.</param>
215+ /// <returns>The first Controller object with the matching axis name, or null if not found.</returns>
216+ public InputAxisControllerBase < T > . Controller GetController ( string axisName )
217+ {
218+ int i = GetControllerIndex ( axisName ) ;
219+ return i < 0 ? null : Controllers [ i ] ;
220+ }
221+
222+ /// <summary>
223+ /// Triggers recentering for a given axis, and also cancels any input currently in progrress for that axis.
224+ /// </summary>
225+ /// <param name="axisName">The name of the axis, as it appears in the inspector.</param>
226+ /// <returns>True if the axis was found and recentering triggered, false otherwise</returns>
227+ public bool TriggerRecentering ( string axisName )
228+ {
229+ int i = GetControllerIndex ( axisName ) ;
230+ if ( i >= 0 )
231+ {
232+ var c = Controllers [ i ] ;
233+ c . Driver . CancelCurrentInput ( ref m_Axes [ i ] . DrivenAxis ( ) ) ;
234+ m_Axes [ i ] . DrivenAxis ( ) . TriggerRecentering ( ) ;
235+ }
236+ return i >= 0 ;
237+ }
238+ }
200239
201240 /// <summary>
202241 /// This is a base class for a behaviour that is used to drive IInputAxisOwner behaviours,
@@ -331,6 +370,22 @@ protected void UpdateControllers(float deltaTime)
331370
332371 m_ControllerManager . UpdateControllers ( this , deltaTime ) ;
333372 }
373+
374+ /// <summary>
375+ /// Get the controller for a given axis name. The axis name is the name displayed
376+ /// for the axis foldout on the inspector.
377+ /// </summary>
378+ /// <param name="axisName">The name of the axis, as it appears in the inspector.</param>
379+ /// <returns>The first Controller object with the matching axis name, or null if not found.</returns>
380+ public Controller GetController ( string axisName ) => m_ControllerManager . GetController ( axisName ) ;
381+
382+ /// <summary>
383+ /// Triggers recentering for a given axis, and also cancels any input currently in progress for that axis.
384+ /// This ensures that the recentering begins immediately.
385+ /// </summary>
386+ /// <param name="axisName">The name of the axis, as it appears in the inspector.</param>
387+ /// <returns>True if the axis was found and recentering triggered, false otherwise</returns>
388+ public bool TriggerRecentering ( string axisName ) => m_ControllerManager . TriggerRecentering ( axisName ) ;
334389 }
335390}
336391
0 commit comments