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