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