-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScreenUpdate.cs
96 lines (73 loc) · 3.02 KB
/
ScreenUpdate.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class ScreenUpdate : MonoBehaviour
{
public GameObject[] screens = new GameObject[4];
public Texture ballad;
public Texture hiphop;
public Texture dance;
public Texture rock;
public Texture trot;
public Texture indie;
public Texture pop;
public Texture none;
public Texture black;
private Texture texture;
[System.Serializable]
public class Api
{
public string name;
public string result;
}
public void screenUpda(){
StartCoroutine(screenChange());
}
IEnumerator screenChange(){
UnityWebRequest request = UnityWebRequest.Get("http://digger.works:12023/getLastDB");
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
{
string data = request.downloadHandler.text;
Api apiResult = JsonUtility.FromJson<Api>(data);
if(apiResult.result[2].Equals('0')) texture = rock;
else if(apiResult.result[2].Equals('1')) texture = ballad;
else if(apiResult.result[2].Equals('2')) texture = indie;
else if(apiResult.result[2].Equals('3')) texture = trot;
else if(apiResult.result[2].Equals('4')) texture = hiphop;
else if(apiResult.result[2].Equals('5')) texture = dance;
else if(apiResult.result[2].Equals('6')) texture = pop;
else texture = none;
yield return new WaitForSeconds(0.1f);
Renderer renderer;
Material material;
for(int i=0; i<4; i++){
renderer = screens[i].GetComponent<Renderer>();
material = renderer.material;
material.mainTexture = black;
}
yield return new WaitForSeconds(Random.Range(0.3f, 0.7f));
renderer = screens[0].GetComponent<Renderer>();
material = renderer.material;
material.mainTexture = texture;
yield return new WaitForSeconds(Random.Range(0.3f, 0.7f));
renderer = screens[1].GetComponent<Renderer>();
material = renderer.material;
material.mainTexture = texture;
yield return new WaitForSeconds(Random.Range(0.3f, 0.7f));
renderer = screens[2].GetComponent<Renderer>();
material = renderer.material;
material.mainTexture = texture;
yield return new WaitForSeconds(Random.Range(0.3f, 0.95f));
renderer = screens[3].GetComponent<Renderer>();
material = renderer.material;
material.mainTexture = texture;
// for(int i=0; i<4; i++){
// renderer = screens[i].GetComponent<Renderer>();
// material = renderer.material;
// material.mainTexture = texture;
// }
}
}
}