Tanoda
SampleTearDown.cs
Go to the documentation of this file.
1
9using UnityEngine;
10
14public class SampleTearDown : MonoBehaviour
15{
16#if !UNITY_WEBGL
18
19 // Initialization
20 void Start()
21 {
22 serialController = GameObject.Find("SerialController").GetComponent<SerialController>();
23
25
26 Debug.Log("Press 1 or 2 to execute some actions");
27 }
28
29 // Executed each frame
30 void Update()
31 {
32 //---------------------------------------------------------------------
33 // Send data
34 //---------------------------------------------------------------------
35
36 // If you press one of these keys send it to the serial device. A
37 // sample serial device that accepts this input is given in the README.
38 if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1))
39 {
40 Debug.Log("Sending lights ON");
42 }
43
44 if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2))
45 {
46 Debug.Log("Sending lights OFF");
48 }
49
50
51 //---------------------------------------------------------------------
52 // Receive data
53 //---------------------------------------------------------------------
54
55 var message = serialController.ReadSerialMessage();
56
57 if (message == null)
58 return;
59
60 // Check if the message is plain data or a connect/disconnect event.
61 if (ReferenceEquals(message, SerialController.SERIAL_DEVICE_CONNECTED))
62 Debug.Log("Connection established");
63 else if (ReferenceEquals(message, SerialController.SERIAL_DEVICE_DISCONNECTED))
64 Debug.Log("Connection attempt failed or disconnection detected");
65 else
66 Debug.Log("Message arrived: " + message);
67 }
68
69 // Tear-down function for the hardware at the other side of the COM port
70 public void lightsShutdown()
71 {
72 Debug.Log("Executing teardown");
74 }
75#endif
76}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void lightsShutdown()
SerialController serialController
const string SERIAL_DEVICE_CONNECTED
string ReadSerialMessage()
const string SERIAL_DEVICE_DISCONNECTED
void SendSerialMessage(string message)
void SetTearDownFunction(TearDownFunction userFunction)