Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TouchPressControl.cs 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using UnityEngine.InputSystem.Layouts;
  3. using UnityEngine.InputSystem.LowLevel;
  4. using UnityEngine.InputSystem.Utilities;
  5. namespace UnityEngine.InputSystem.Controls
  6. {
  7. /// <summary>
  8. /// A button that reads its pressed state from <see cref="TouchControl.phase"/>.
  9. /// </summary>
  10. /// <remarks>
  11. /// This control is used by <see cref="TouchControl"/> to link <see cref="TouchControl.press"/>
  12. /// to <see cref="TouchControl.phase"/>. It will return 1 as long as the value of
  13. /// phase is <see cref="TouchPhase.Began"/>, <see cref="TouchPhase.Stationary"/>, or
  14. /// <see cref="TouchPhase.Moved"/>, i.e. as long as the touch is in progress. For
  15. /// all other phases, it will return 0.
  16. /// </remarks>
  17. /// <seealso cref="TouchControl"/>
  18. [InputControlLayout(hideInUI = true)]
  19. public class TouchPressControl : ButtonControl
  20. {
  21. /// <inheritdoc />
  22. protected override void FinishSetup()
  23. {
  24. base.FinishSetup();
  25. if (!stateBlock.format.IsIntegerFormat())
  26. throw new NotSupportedException(
  27. $"Non-integer format '{stateBlock.format}' is not supported for TouchButtonControl '{this}'");
  28. }
  29. /// <inheritdoc />
  30. public override unsafe float ReadUnprocessedValueFromState(void* statePtr)
  31. {
  32. var valuePtr = (byte*)statePtr + (int)m_StateBlock.byteOffset;
  33. var uintValue = MemoryHelpers.ReadMultipleBitsAsUInt(valuePtr, m_StateBlock.bitOffset, m_StateBlock.sizeInBits);
  34. var phaseValue = (TouchPhase)uintValue;
  35. var value = 0.0f;
  36. if (phaseValue == TouchPhase.Began || phaseValue == TouchPhase.Stationary ||
  37. phaseValue == TouchPhase.Moved)
  38. value = 1;
  39. return Preprocess(value);
  40. }
  41. public override unsafe void WriteValueIntoState(float value, void* statePtr)
  42. {
  43. throw new NotSupportedException();
  44. }
  45. }
  46. }