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)]
[Scripting.Preserve]
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 intValue = MemoryHelpers.ReadIntFromMultipleBits(valuePtr, m_StateBlock.bitOffset, m_StateBlock.sizeInBits);
var phaseValue = (TouchPhase)intValue;
var value = 0.0f;
if (phaseValue == TouchPhase.Began || phaseValue == TouchPhase.Stationary ||
phaseValue == TouchPhase.Moved)
value = 1;
return Preprocess(value);
}
}
}