2020-08-07 00:43:30 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.InputSystem;
|
2020-08-07 01:06:00 +02:00
|
|
|
|
using NeonTea.Quakeball.Interface;
|
2020-08-07 00:43:30 +02:00
|
|
|
|
|
|
|
|
|
namespace NeonTea.Quakeball.Util {
|
|
|
|
|
public class PressedActionDisplayer : MonoBehaviour {
|
|
|
|
|
private InputAction Initializer;
|
|
|
|
|
private InputAction AnyAction;
|
|
|
|
|
|
|
|
|
|
private InputActionRebindingExtensions.RebindingOperation Rebinding;
|
2020-08-07 01:06:00 +02:00
|
|
|
|
private bool InitializedFromTerminal = false;
|
2020-08-07 00:43:30 +02:00
|
|
|
|
|
|
|
|
|
private void Awake() {
|
|
|
|
|
AnyAction = new InputAction("InputAction displayer", binding: "*/*");
|
|
|
|
|
|
|
|
|
|
Initializer = new InputAction("Display the next InputAction", binding: "<Keyboard>/f1");
|
|
|
|
|
Initializer.Enable();
|
|
|
|
|
Initializer.performed += _ => {
|
2020-08-07 01:06:00 +02:00
|
|
|
|
InitializedFromTerminal = false;
|
|
|
|
|
StartWaiting();
|
2020-08-07 00:43:30 +02:00
|
|
|
|
};
|
2020-08-07 01:06:00 +02:00
|
|
|
|
|
|
|
|
|
Terminal.Singleton.RegisterCommand("read", args => {
|
|
|
|
|
if (args.Length == 0) {
|
|
|
|
|
InitializedFromTerminal = true;
|
|
|
|
|
StartWaiting();
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
2020-08-07 01:42:59 +02:00
|
|
|
|
Terminal.Singleton.Println($"<color={Terminal.ERROR_COLOR}>The 'read' command takes no arguments.</color>");
|
2020-08-07 01:06:00 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-08-07 01:42:59 +02:00
|
|
|
|
}, "read - Waits for an input action, and then prints it.");
|
2020-08-07 01:06:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartWaiting() {
|
|
|
|
|
if (!InitializedFromTerminal) {
|
|
|
|
|
Debug.Log("Waiting for InputAction to display...");
|
|
|
|
|
} else {
|
2020-08-07 01:42:59 +02:00
|
|
|
|
Terminal.Singleton.Println("Waiting for InputAction to display...");
|
2020-08-07 01:06:00 +02:00
|
|
|
|
}
|
|
|
|
|
Rebinding = AnyAction.PerformInteractiveRebinding().Start();
|
2020-08-07 00:43:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update() {
|
|
|
|
|
if (Rebinding != null && Rebinding.completed) {
|
|
|
|
|
string Binding = Rebinding.action.ToString();
|
2020-08-07 01:06:00 +02:00
|
|
|
|
Rebinding.Dispose();
|
2020-08-07 00:43:30 +02:00
|
|
|
|
int Index = Binding.IndexOf("/") + 1;
|
2020-08-07 01:06:00 +02:00
|
|
|
|
Binding = Binding.Substring(Index, Binding.Length - Index - 1);
|
|
|
|
|
if (!InitializedFromTerminal) {
|
|
|
|
|
Debug.Log("Binding: " + Binding);
|
|
|
|
|
} else {
|
2020-08-07 01:42:59 +02:00
|
|
|
|
Terminal.Singleton.Println("Binding: " + Binding);
|
2020-08-07 01:06:00 +02:00
|
|
|
|
}
|
2020-08-07 00:43:30 +02:00
|
|
|
|
Rebinding = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|