-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionTest.cs
More file actions
80 lines (67 loc) · 1.8 KB
/
Copy pathConnectionTest.cs
File metadata and controls
80 lines (67 loc) · 1.8 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections;
using System.Collections.Generic;
using PythonConnection;
using Unity.VisualScripting;
using UnityEngine;
public class ConnectionTest : MonoBehaviour
{
[Serializable]
private class SendingData
{
public SendingData(int testValue0, List<float> testValue1)
{
this.testValue0 = testValue0;
this.testValue1 = testValue1;
}
public int testValue0;
[SerializeField]
private List<float> testValue1;
}
void Start()
{
PythonConnector.instance.RegisterAction(typeof(TestDataClass), OnDataReceived);
if (PythonConnector.instance.StartConnection())
{
Debug.Log("Connected");
}
else
{
Debug.Log("Connection Failed");
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
PythonConnector.instance.StopConnection();
Debug.Log("Stop");
}
}
public void OnTimeout()
{
Debug.Log("Timeout");
}
public void OnStop()
{
Debug.Log("Stopped");
}
public void OnDataReceived(DataClass data)
{
TestDataClass testData = data as TestDataClass;
Debug.Log("testValue0: " + testData.testValue0);
foreach (float v in testData.v1)
{
Debug.Log("testValue1: " + v);
}
int v1 = UnityEngine.Random.Range(0, 100);
List<float> v2 = new List<float>()
{
UnityEngine.Random.Range(0.1f, 0.9f),
UnityEngine.Random.Range(0.1f, 0.9f)
};
SendingData sendingData = new SendingData(v1, v2);
Debug.Log("Sending Data: " + v1 + ", " + v2[0] + ", " + v2[1]);
PythonConnector.instance.Send("test", sendingData);
}
}