AnyKeyControl.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine.InputSystem.Layouts;
  2. using UnityEngine.InputSystem.LowLevel;
  3. ////REVIEW: generalize this to AnyButton and add to more devices?
  4. namespace UnityEngine.InputSystem.Controls
  5. {
  6. /// <summary>
  7. /// A control that simply checks the entire state it's been assigned
  8. /// for whether there's any non-zero bytes. If there are, the control
  9. /// returns 1.0; otherwise it returns 0.0.
  10. /// </summary>
  11. /// <remarks>
  12. /// This control is used by <see cref="Keyboard.anyKey"/> to create a button
  13. /// that is toggled on as long as any of the keys on the keyboard is pressed.
  14. /// </remarks>
  15. /// <seealso cref="Keyboard.anyKey"/>
  16. [InputControlLayout(hideInUI = true)]
  17. [Scripting.Preserve]
  18. public class AnyKeyControl : ButtonControl
  19. {
  20. ////TODO: wasPressedThisFrame and wasReleasedThisFrame
  21. /// <summary>
  22. /// Default initialization. Sets state size to 1 bit and format to
  23. /// <see cref="InputStateBlock.FormatBit"/>.
  24. /// </summary>
  25. public AnyKeyControl()
  26. {
  27. m_StateBlock.sizeInBits = 1; // Should be overridden by whoever uses the control.
  28. m_StateBlock.format = InputStateBlock.FormatBit;
  29. }
  30. /// <inheritdoc />
  31. public override unsafe float ReadUnprocessedValueFromState(void* statePtr)
  32. {
  33. return this.CheckStateIsAtDefault(statePtr) ? 0.0f : 1.0f;
  34. }
  35. }
  36. }