-
Notifications
You must be signed in to change notification settings - Fork 0
/
PostData.cs
166 lines (153 loc) · 4.48 KB
/
PostData.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Michsky.UI.ModernUIPack;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class PostData : MonoBehaviour
{
public GameObject Interactive;
private void Start()
{
StartCoroutine(ExampleCoroutine());
#region Off All
#endregion
}
#region Rotate
public void RotateOn()
{
StartCoroutine(EventOn("ROTATE"));
}
public void RotateOff()
{
StartCoroutine(EventOff("ROTATE"));
}
#endregion
#region Grid
public void GridOn()
{
StartCoroutine(EventOn("GRID"));
}
public void GridOff()
{
StartCoroutine(EventOff("GRID"));
}
public void onClickGrid()
{
if (Interactive.GetComponent<SwitchManager>().isOn == true)
{
StartCoroutine(EventOff("GRID"));
}
else
StartCoroutine(EventOn("GRID"));
}
#endregion
#region ABM
public void ABMOn()
{
StartCoroutine(EventOn("ABM"));
}
public void ABMOff()
{
StartCoroutine(EventOff("ABM"));
}
#endregion
#region Geojson
public void GEOJSONOn()
{
StartCoroutine(EventOn("GEOJSON"));
}
public void GEOJSONOff()
{
StartCoroutine(EventOff("GEOJSON"));
}
#endregion
#region Aggregated Trips
public void AggregatedTripsOn()
{
StartCoroutine(EventOn("AGGREGATED_TRIPS"));
}
public void AggregatedTripsOff()
{
StartCoroutine(EventOff("AGGREGATED_TRIPS"));
}
#endregion
#region Access
public void AccessOn()
{
StartCoroutine(EventOn("ACCESS"));
}
public void AccessOff()
{
StartCoroutine(EventOff("ACCESS"));
}
#endregion
#region Textual
public void TextualOn()
{
StartCoroutine(EventOn("TEXTUAL"));
}
public void TextualOff()
{
StartCoroutine(EventOff("TEXTUAL"));
}
#endregion
#region Shadows
public void ShadowsOn()
{
StartCoroutine(EventOn("SHADOWS"));
}
public void ShadowsOff()
{
StartCoroutine(EventOff("SHADOWS"));
}
#endregion
IEnumerator EventOn(string method)
{
string bodyJsonString = "{\"table\":\"hcm_scenario_0\"," + $"\"option\":\"{method}\"," + "\"mode\":\"ON\"}";
var request = new UnityWebRequest($"https://csl-hcmc.com/api/set-option?", "POST");
byte[] bodyRaw = Encoding.UTF8.GetBytes(bodyJsonString);
request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();
Debug.Log("Status Code: " + request.responseCode);
}
IEnumerator EventOff(string method)
{
string bodyJsonString = "{\"table\":\"hcm_scenario_0\"," + $"\"option\":\"{method}\"," + "\"mode\":\"OFF\"}";
var request = new UnityWebRequest($"https://csl-hcmc.com/api/set-option?", "POST");
byte[] bodyRaw = Encoding.UTF8.GetBytes(bodyJsonString);
request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
yield return request.SendWebRequest();
Debug.Log("Status Code: " + request.responseCode);
}
IEnumerator ExampleCoroutine()
{
//Print the time of when the function is first called.
Debug.Log("Started Coroutine at timestamp : " + Time.time);
//yield on a new YieldInstruction that waits for 5 seconds.
yield return new WaitForSeconds(1f);
GridOff();
//yield return new WaitForSeconds(1.5f);
//RotateOff();
yield return new WaitForSeconds(1f);
ABMOff();
yield return new WaitForSeconds(0.5f);
GEOJSONOff();
yield return new WaitForSeconds(0.5f);
AggregatedTripsOff();
yield return new WaitForSeconds(0.5f);
AccessOff();
yield return new WaitForSeconds(0.5f);
TextualOff();
yield return new WaitForSeconds(0.5f);
ShadowsOff();
yield return new WaitForSeconds(0.5f);
//After we have waited 5 seconds print the time again.
Debug.Log("Finished Coroutine at timestamp : " + Time.time);
}
}