暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TouchPhaseControl.cs 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine.InputSystem.Layouts;
  2. using UnityEngine.InputSystem.LowLevel;
  3. // Unfortunately, C# (at least up to version 6) does not support enum type constraints. There's
  4. // ways to work around it in some situations (https://stackoverflow.com/questions/79126/create-generic-method-constraining-t-to-an-enum)
  5. // but not in a way that will allow us to convert an int to the enum type.
  6. ////TODO: allow this to be stored in less than 32bits
  7. namespace UnityEngine.InputSystem.Controls
  8. {
  9. /// <summary>
  10. /// A control reading a <see cref="TouchPhase"/> value.
  11. /// </summary>
  12. /// <remarks>
  13. /// This is used mainly by <see cref="Touchscreen"/> to read <see cref="TouchState.phase"/>.
  14. /// </remarks>
  15. /// <seealso cref="Touchscreen"/>
  16. [InputControlLayout(hideInUI = true)]
  17. public class TouchPhaseControl : InputControl<TouchPhase>
  18. {
  19. /// <summary>
  20. /// Default-initialize the control.
  21. /// </summary>
  22. /// <remarks>
  23. /// Format of the control is <see cref="InputStateBlock.FormatInt"/>
  24. /// by default.
  25. /// </remarks>
  26. public TouchPhaseControl()
  27. {
  28. m_StateBlock.format = InputStateBlock.FormatInt;
  29. }
  30. /// <inheritdoc />
  31. public override unsafe TouchPhase ReadUnprocessedValueFromState(void* statePtr)
  32. {
  33. var intValue = stateBlock.ReadInt(statePtr);
  34. return (TouchPhase)intValue;
  35. }
  36. /// <inheritdoc />
  37. public override unsafe void WriteValueIntoState(TouchPhase value, void* statePtr)
  38. {
  39. var valuePtr = (byte*)statePtr + (int)m_StateBlock.byteOffset;
  40. *(TouchPhase*)valuePtr = value;
  41. }
  42. }
  43. }