mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-15 17:59:22 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using Facepunch.XR;
|
|
|
|
namespace Sandbox.VR;
|
|
|
|
/// <summary>
|
|
/// Represents a VR digital input action (e.g. X button)
|
|
/// </summary>
|
|
public struct DigitalInput
|
|
{
|
|
internal readonly InputBooleanActionState _data;
|
|
|
|
/// <summary>
|
|
/// The current value of this input - true if pressed, false if not pressed.
|
|
/// </summary>
|
|
public readonly bool IsPressed => _data.state != 0;
|
|
|
|
/// <summary>
|
|
/// The previous value of this input - true if it was pressed, false if it was not pressed.
|
|
/// </summary>
|
|
public readonly bool WasPressed { get; private init; }
|
|
|
|
/// <summary>
|
|
/// How much <see cref="IsPressed"/> has changed since the last update.
|
|
/// </summary>
|
|
public readonly bool Delta { get; private init; }
|
|
|
|
/// <summary>
|
|
/// Whether or not this action is currently accessible (if false, then <see cref="IsPressed"/> will always be false and will never change).
|
|
/// </summary>
|
|
public readonly bool Active => _data.isActive;
|
|
|
|
internal DigitalInput( DigitalInput? previous, VRNative.BooleanAction action, InputSource inputSource )
|
|
{
|
|
_data = VRNative.GetBooleanActionState( action, inputSource );
|
|
|
|
if ( previous != null )
|
|
{
|
|
WasPressed = previous.Value.IsPressed;
|
|
Delta = IsPressed != WasPressed;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Implicitly returns <see cref="IsPressed"/> as a <see cref="bool"/>.
|
|
/// </summary>
|
|
public static implicit operator bool( DigitalInput o )
|
|
{
|
|
return o.IsPressed;
|
|
}
|
|
}
|