using System;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
namespace UnityEngine.InputSystem.Controls
{
///
/// A button that reads its pressed state from .
///
///
/// This control is used by to link
/// to . It will return 1 as long as the value of
/// phase is , , or
/// , i.e. as long as the touch is in progress. For
/// all other phases, it will return 0.
///
///
[InputControlLayout(hideInUI = true)]
public class TouchPressControl : ButtonControl
{
///
protected override void FinishSetup()
{
base.FinishSetup();
if (!stateBlock.format.IsIntegerFormat())
throw new NotSupportedException(
$"Non-integer format '{stateBlock.format}' is not supported for TouchButtonControl '{this}'");
}
///
public override unsafe float ReadUnprocessedValueFromState(void* statePtr)
{
var valuePtr = (byte*)statePtr + (int)m_StateBlock.byteOffset;
var uintValue = MemoryHelpers.ReadMultipleBitsAsUInt(valuePtr, m_StateBlock.bitOffset, m_StateBlock.sizeInBits);
var phaseValue = (TouchPhase)uintValue;
var value = 0.0f;
if (phaseValue == TouchPhase.Began || phaseValue == TouchPhase.Stationary ||
phaseValue == TouchPhase.Moved)
value = 1;
return Preprocess(value);
}
public override unsafe void WriteValueIntoState(float value, void* statePtr)
{
throw new NotSupportedException();
}
}
}