-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cs
140 lines (119 loc) · 3.79 KB
/
main.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class main : MonoBehaviour {
public GameObject LedStringPrefab;
public Camera Main, Top, Front;
public UnityEngine.UI.Text errortext;
public UnityEngine.UI.InputField portfield;
bool oneshot ;
public List<GameObject> Strings;
public List<GameObject> LEDS;
public List<Color> colors;
public socketinput socketin;
// Use this for initialization
void Start () {
Main.gameObject.SetActive(false);
Top.gameObject.SetActive(false);
Front.gameObject.SetActive(true);
//socketin = Instantiate(new socketinput());
LEDS = new List<GameObject>();
Strings = new List<GameObject>();
colors = new List<Color>();
if (LedStringPrefab != null)
{
for(int ii =0; ii <25; ii++)
{
var ledstring = Instantiate(LedStringPrefab);
Strings.Add(ledstring);
}
}
oneshot = true;
}
// Update is called once per frame
void Update () {
#region rotate LedStrings to right position
if (oneshot)
{
int kk = 0;
foreach (GameObject ledstring in Strings)
{
ledstring.transform.Rotate(0f, 14.4f * kk, 0f);
kk++;
}
//vom Jan :)
for (int ii = 0; ii < Strings.Count; ii++)
{
var off = (ii / 5) % 2;
for (int jj = 0; jj < Strings[ii].transform.childCount; jj++)
{
var parent = Strings[ii].transform;
if ((ii + off) % 2 == 0)
{
LEDS.Add(parent.GetChild(jj).gameObject);
}
else
{
LEDS.Add(parent.GetChild((parent.childCount - 1) - jj).gameObject);
}
}
}
oneshot = false;
}
#endregion
if(Input.GetKeyDown(KeyCode.F1))
{
Main.gameObject.SetActive(false);
Top.gameObject.SetActive(false);
Front.gameObject.SetActive(true);
}
if (Input.GetKeyDown(KeyCode.F2))
{
Main.gameObject.SetActive(false);
Top.gameObject.SetActive(true);
Front.gameObject.SetActive(false);
}
if (Input.GetKeyDown(KeyCode.F3))
{
Main.gameObject.SetActive(true);
Top.gameObject.SetActive(false);
Front.gameObject.SetActive(false);
}
if(Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
errortext.text = socketin.debug;
colors = socketin.DataOut;
if(colors.Count == 250)
{
SetColors(LEDS);
}
}
public void Setport()
{
socketin.Port = System.Convert.ToInt32(portfield.text);
socketin.ListenToPort();
}
void SetColors(List<GameObject> myLeds)
{
if (myLeds.Count != colors.Count/2)
{
errortext.text = "Less than 250 colors defined. wont Set!";
return;
}
else errortext.text = "";
for (int ii = 0; ii < colors.Count; ii++)
{
myLeds[ii].GetComponent<MeshRenderer>().material.SetColor("_MKGlowColor",colors[ii]);
}
}
public void GetColors(List<GameObject> myLeds)
{
foreach(GameObject led in myLeds)
{
var col = led.GetComponent<Material>().color;
colors.Add(col);
}
}
}