Input tester
Shows the local player's input: the sticks and every button from StageTimeInput
(whether it is held and how far it is pressed with GetButtonValue), and the last input events with the hand they
came from. Input is local, so every player sees their own controls on the same board.
InputTester.cs
using StageTime.SDK;
using TMPro;
using UnityEngine;
/// <summary>
/// Shows the local player's input: the sticks and every button from StageTimeInput (held, and how far it is pressed),
/// and the last input events with the hand they came from. Input is local, so each player sees their own.
/// </summary>
public class InputTester : StageTimeBehaviour
{
public TMP_Text stateLabel;
public TMP_Text eventsLabel;
private string[] events = new string[8];
private string lastAxis = "-";
private bool eventsChanged = true;
private float nextRefresh;
private void Update()
{
if (Time.time < nextRefresh) return;
nextRefresh = Time.time + 0.05f;
if (stateLabel != null)
{
Vector2 move = StageTimeInput.move;
Vector2 look = StageTimeInput.look;
stateLabel.text = "Move " + Number(move.x) + " " + Number(move.y)
+ "\nLook " + Number(look.x) + " " + Number(look.y)
+ Row("Jump", STInputButton.Jump)
+ Row("Use", STInputButton.Use)
+ Row("Secondary Use", STInputButton.SecondaryUse)
+ Row("Grab", STInputButton.Grab)
+ Row("Drop", STInputButton.Drop);
}
if (eventsChanged && eventsLabel != null)
{
eventsChanged = false;
string text = "Last axis event: " + lastAxis + "\n";
for (int i = 0; i < events.Length; i++)
if (events[i] != null) text += "\n" + events[i];
eventsLabel.text = text;
}
}
public override void OnInputJump(bool value, STInputArgs args) { Log("Jump", value, args); }
public override void OnInputUse(bool value, STInputArgs args) { Log("Use", value, args); }
public override void OnInputSecondaryUse(bool value, STInputArgs args) { Log("SecondaryUse", value, args); }
public override void OnInputGrab(bool value, STInputArgs args) { Log("Grab", value, args); }
public override void OnInputDrop(bool value, STInputArgs args) { Log("Drop", value, args); }
public override void OnInputMoveHorizontal(float value, STInputArgs args) { Axis("MoveHorizontal", value, args); }
public override void OnInputMoveVertical(float value, STInputArgs args) { Axis("MoveVertical", value, args); }
public override void OnInputLookHorizontal(float value, STInputArgs args) { Axis("LookHorizontal", value, args); }
public override void OnInputLookVertical(float value, STInputArgs args) { Axis("LookVertical", value, args); }
private void Log(string name, bool value, STInputArgs args)
{
for (int i = events.Length - 1; i > 0; i--) events[i] = events[i - 1];
events[0] = Time.time.ToString("0.00") + " On" + "Input" + name + " "
+ (value ? "<color=#6f6>pressed</color>" : "<color=#f88>released</color>") + " " + Hand(args);
eventsChanged = true;
}
private void Axis(string name, float value, STInputArgs args)
{
lastAxis = name + " " + Number(value) + " " + Hand(args);
eventsChanged = true;
}
private string Row(string name, STInputButton button)
{
bool held = StageTimeInput.GetButton(button);
float value = StageTimeInput.GetButtonValue(button);
int filled = Mathf.RoundToInt(value * 10f);
string bar = "<color=#6cf>";
for (int i = 0; i < 10; i++)
{
if (i == filled) bar += "</color><color=#444>";
bar += "|";
}
bar += "</color>";
return "\n" + name + " " + (held ? "<color=#6f6>held</color>" : "<color=#888>up</color>") + " " + bar + " " + value.ToString("0.00");
}
private string Hand(STInputArgs args)
{
return args.handType == STInputHand.Left ? "(left)" : "(right)";
}
private string Number(float value)
{
return (value >= 0f ? " " : "") + value.ToString("0.00");
}
}