46 lines
1.0 KiB
C#
46 lines
1.0 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class InputTester : MonoBehaviour
|
|
{
|
|
private TextMeshProUGUI text;
|
|
private bool _enabled = false;
|
|
void Start()
|
|
{
|
|
text = GetComponent<TextMeshProUGUI>();
|
|
UpdateColor();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
ComPortController.InputRecieved -= ComPortController_InputRecieved;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Alpha9))
|
|
{
|
|
_enabled = !_enabled;
|
|
UpdateColor();
|
|
}
|
|
}
|
|
|
|
private void ComPortController_InputRecieved(string input)
|
|
{
|
|
text.text = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\n"+ input;
|
|
}
|
|
|
|
public void UpdateColor()
|
|
{
|
|
Color color = _enabled ? Color.white : Color.clear;
|
|
text.color = color;
|
|
|
|
if(_enabled)
|
|
ComPortController.InputRecieved += ComPortController_InputRecieved;
|
|
else
|
|
{
|
|
ComPortController.InputRecieved -= ComPortController_InputRecieved;
|
|
}
|
|
}
|
|
}
|