/// <summary> /// Return true if the given control is actuated. /// </summary> /// <param name="control"></param> /// <param name="threshold">Magnitude threshold that the control must match or exceed to be considered actuated. /// An exception to this is the default value of zero. If threshold is zero, the control must have a magnitude /// greater than zero.</param> /// <returns></returns> /// <remarks> /// Actuation is defined as a control having a magnitude (<see cref="InputControl.EvaluateMagnitude()"/> /// greater than zero or, if the control does not support magnitudes, has been moved from its default /// state. /// /// In practice, this means that when actuated, a control will produce a value other than its default /// value. /// </remarks> public static bool IsActuated(this InputControl control, float threshold = 0) { // First perform cheap memory check. If we're in default state, we don't // need to invoke virtuals on the control. if (control.CheckStateIsAtDefault()) { return(false); } // Check magnitude of actuation. var magnitude = control.EvaluateMagnitude(); if (magnitude < 0) { ////REVIEW: we probably want to do a value comparison on this path to compare it to the default value return(true); } if (Mathf.Approximately(threshold, 0)) { return(magnitude > 0); } return(magnitude >= threshold); }
public static unsafe bool CheckStateIsAtDefaultIgnoringNoise(this InputControl control, void *statePtr) { if (control == null) { throw new ArgumentNullException(nameof(control)); } if (statePtr == null) { throw new ArgumentNullException(nameof(statePtr)); } return(control.CheckStateIsAtDefault(statePtr, InputStateBuffers.s_NoiseMaskBuffer)); }