Skip to main content

ControllerDPad

A class in Root.Township, the global namespace.

Turns a hand's touchpad and thumbstick input into numbered directions and four-way swipes. Made by PlayerInput; call OnEnable and Update to drive it. Client side.

Constructors​

MemberWhat it is
ControllerDPad(PlayerInput playerInput)Creates a ControllerDPad from playerInput.

Fields​

14 private and internal fields
MemberWhat it is
private float broaderDirectionSensitivitySquared half of the swipe sensitivity.
private int buttonCountNumber of direction sectors around the pad. 12.
private Vector2 currentTouchPadLast touchpad position read.
private Vector2 debugVectorTest input used instead of the touchpad when useDebugVector is on.
private float innerRadiusSquared radius of the centre zone.
private ControllerInput inputThe raw controller input it reads.
private bool isClockwiseForRightHandMirrors the angle for the right hand so directions run the same way on both hands.
private int oldTouchPadDirectionDirection from the previous check, to detect changes.
private PlayerInput playerInputThe hand's PlayerInput.
private float rotationOffsetAngle offset in degrees applied before splitting into sectors. -90.
private float swipeSensitivitySquared minimum swipe length.
private float[] swipeSentivityLevelsSwipe lengths for each settings level: 1.5, 1 and 0.5.
private Vector2 touchStartTouchpad position when the touch began.
private bool useDebugVectorUse debugVector instead of the real touchpad.

Properties​

MemberWhat it is
int CurrentDpadDirection { get; private set; }Touchpad sector (1 to 12), 0 when touched near the centre, -1 when not touched. Mirrored for the right hand.
int CurrentSwipeDirection { get; private set; }Direction of the last swipe: 0 right, 1 up, 2 left, 3 down.
Vector2 CurrentSwipeMovement { get; }How far the touch has moved since the touchpad was pressed.
int CurrentThumbStickBroadDirection { get; private set; }Declared but never set in this build; stays -1.
int CurrentThumbStickDirection { get; private set; }Thumbstick sector (1 to 12), or -1 inside the dead zone.

Events​

MemberWhat it is
event Action<int> SwipeExecutedRaised when the touchpad is released, with the swipe direction or -1 if the movement was too short.
event Action<int> TouchChangedRaised when CurrentDpadDirection changes.

Methods​

MemberWhat it is
void OnDisable()Stops listening for touchpad press and release.
void OnEnable()Starts listening for touchpad press and release and reads the swipe sensitivity setting.
void Update()Recalculates the touchpad and thumbstick directions.
protected override void Finalize()Unhooks the swipe sensitivity settings listener.
5 private and internal methods
MemberWhat it is
private void CalculateGestureDirection()Sets CurrentThumbStickDirection from the thumbstick angle, split into buttonCount sectors.
private void CalculateSwipe(PlayerInput playerInput)On touch release, works out the swipe direction (0 right, 1 up, 2 left, 3 down) and raises SwipeExecuted, or -1 if too short.
private void CalculateSwipeDirection()Sets CurrentDpadDirection from the touchpad position and raises TouchChanged when it changes. 0 is the centre.
private void CheckForSwipeSensitivityLevelInSettings(GameSettings settings)Reads the swipe sensitivity level from game settings and squares it for distance checks.
private void PadTouched(PlayerInput playerInput)On touch start, stores the start point and updates the direction.

Used in​

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