A game about forced loneliness, made by TACStudios
1using UnityEngine.InputSystem.LowLevel; 2using UnityEngine.InputSystem.Utilities; 3 4////TODO: this or the layout system needs to detect when the format isn't supported by the control 5 6namespace UnityEngine.InputSystem.Controls 7{ 8 /// <summary> 9 /// A generic input control reading integer values. 10 /// </summary> 11 public class IntegerControl : InputControl<int> 12 { 13 /// <summary> 14 /// Default-initialize an integer control. 15 /// </summary> 16 public IntegerControl() 17 { 18 m_StateBlock.format = InputStateBlock.FormatInt; 19 } 20 21 /// <inheritdoc/> 22 public override unsafe int ReadUnprocessedValueFromState(void* statePtr) 23 { 24 switch (m_OptimizedControlDataType) 25 { 26 case InputStateBlock.kFormatInt: 27 return *(int*)((byte*)statePtr + (int)m_StateBlock.byteOffset); 28 default: 29 return m_StateBlock.ReadInt(statePtr); 30 } 31 } 32 33 /// <inheritdoc/> 34 public override unsafe void WriteValueIntoState(int value, void* statePtr) 35 { 36 switch (m_OptimizedControlDataType) 37 { 38 case InputStateBlock.kFormatInt: 39 *(int*)((byte*)statePtr + (int)m_StateBlock.byteOffset) = value; 40 break; 41 default: 42 m_StateBlock.WriteInt(statePtr, value); 43 break; 44 } 45 } 46 47 protected override FourCC CalculateOptimizedControlDataType() 48 { 49 if (m_StateBlock.format == InputStateBlock.FormatInt && 50 m_StateBlock.sizeInBits == 32 && 51 m_StateBlock.bitOffset == 0) 52 return InputStateBlock.FormatInt; 53 return InputStateBlock.FormatInvalid; 54 } 55 } 56}