Skip to main content

DeviceInputController

An abstract class in Root.Township, the global namespace.

Base for a VR device or fly cam input source (SteamVR, OpenXR, fly cam). Fills a ControllerInput each update and pushes it into a PlayerInput. Client side.

Constructors​

MemberWhat it is
protected DeviceInputController(PlayerInput controller)Creates a DeviceInputController from controller.

Fields​

6 private and internal fields
MemberWhat it is
private const float DoubleTapSpeedWindow in seconds (1) for a second tap to count as a double tap.
private float doubleTapTargetReal time by which the second tap must land, or -1 when no tap is pending.
private ControllerInput inputBacking field for Input, created on first use.
private const float PhotoTimeSeconds (0.5) the photo action must be held to count as a long photo.
private float targetPhotoTimeReal time when the held photo action becomes a long photo, or -1.
private bool wasTappingTap state from the last CalculateDoubleTap call, to detect new presses.

Properties​

MemberWhat it is
PlayerInput PlayerInput { get; }The PlayerInput (hand) this device feeds.
protected virtual ControllerInput Input { get; }The reused ControllerInput this device fills each update.

Methods​

MemberWhat it is
void SendInputTo(PlayerInput controller)Fills the input from the device and applies it to the given PlayerInput, firing its events.
abstract void TriggerHaptics(float strength, float frequency, float remainingTime)Plays a vibration with the given strength, frequency and duration.
virtual void UpdatePosition()Per-device hook to update the tracked position. Does nothing in the base class.
protected bool CalculateDoubleTap(bool isTapping)Helper for subclasses: true on the second tap within one second.
protected bool CalculatePhoto(ControllerInput input, bool photoAction)Helper for subclasses: true once the photo action has been held for half a second.
protected abstract void PopulateInput(ControllerInput input)Implemented per device to read the hardware into the input.

Used in​

Members of other types that take, return or hold a DeviceInputController: