File size: 1,718 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 | using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
// Unfortunately, C# (at least up to version 6) does not support enum type constraints. There's
// ways to work around it in some situations (https://stackoverflow.com/questions/79126/create-generic-method-constraining-t-to-an-enum)
// but not in a way that will allow us to convert an int to the enum type.
////TODO: allow this to be stored in less than 32bits
namespace UnityEngine.InputSystem.Controls
{
/// <summary>
/// A control reading a <see cref="TouchPhase"/> value.
/// </summary>
/// <remarks>
/// This is used mainly by <see cref="Touchscreen"/> to read <see cref="TouchState.phase"/>.
/// </remarks>
/// <seealso cref="Touchscreen"/>
[InputControlLayout(hideInUI = true)]
public class TouchPhaseControl : InputControl<TouchPhase>
{
/// <summary>
/// Default-initialize the control.
/// </summary>
/// <remarks>
/// Format of the control is <see cref="InputStateBlock.FormatInt"/>
/// by default.
/// </remarks>
public TouchPhaseControl()
{
m_StateBlock.format = InputStateBlock.FormatInt;
}
/// <inheritdoc />
public override unsafe TouchPhase ReadUnprocessedValueFromState(void* statePtr)
{
var intValue = stateBlock.ReadInt(statePtr);
return (TouchPhase)intValue;
}
/// <inheritdoc />
public override unsafe void WriteValueIntoState(TouchPhase value, void* statePtr)
{
var valuePtr = (byte*)statePtr + (int)m_StateBlock.byteOffset;
*(TouchPhase*)valuePtr = value;
}
}
}
|