//This function handles the mapping of different Arduino inputs, //noted as arg.Value, into actual function calls for different parts //of the game. private void Serial_OnButtonPressed(object sender, ArduinoEventArg arg) { if (delay_timer >= 2) { //Left Arrow if (arg.Value == 1) { UnityMainThreadDispatcher.Instance().Enqueue(() => Selector.prev_option()); delay_timer = 0; } //Launch-OK Button if (arg.Value == 0) { UnityMainThreadDispatcher.Instance().Enqueue(() => { //If on the gameplay screen, this button acts as the ENTER key if (SceneManager.GetActiveScene().name == "Gameplay") { InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN); } //Otherwise it acts as a mouse click else { Manual_Click.click(); } }); delay_timer = 0; } //Right Arrow if (arg.Value == 2) { UnityMainThreadDispatcher.Instance().Enqueue(() => Selector.next_option()); delay_timer = 0; } //Red Rutton if (arg.Value == 3) { UnityMainThreadDispatcher.Instance().Enqueue(() => InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_J)); delay_timer = 0; } //Green Button if (arg.Value == 4) { UnityMainThreadDispatcher.Instance().Enqueue(() => InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_K)); delay_timer = 0; } //Blue Button if (arg.Value == 5) { UnityMainThreadDispatcher.Instance().Enqueue(() => InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_L)); delay_timer = 0; } } }
//Handling for if the angle knob is changed private void Serial_OnKnobChanged(object sender, ArduinoEventArg arg) { //If the rocket is not currently being launched, get the clamped value of the angle if (RocketBehavior.launch == false) { UnityMainThreadDispatcher.Instance().Enqueue(() => { var obj = GameObject.Find("Angle Slider"); if (obj != null) { obj.GetComponent <Slider>().value = arg.Value / 255f; } delay_timer = 0; }); } }