-
Notifications
You must be signed in to change notification settings - Fork 2
/
GUI2.cs
237 lines (196 loc) · 6.11 KB
/
GUI2.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
using UnityEngine;
using System.Collections;
//"Import" scripts
[RequireComponent (typeof (toucher))]
[RequireComponent (typeof (webrequest))]
public class GUI2 : MonoBehaviour {
//Public
public GUIStyle selection_button;
public GUIStyle background_style;
public GUIStyle cube_style;
public GUIStyle popup_style;
public Texture typ1;
public Texture typ2;
public Texture typ3;
public Texture typ4;
public Texture typ5;
public Texture typ6;
public Texture typ7;
public Texture typ8;
public Texture typ9;
public Texture typ10;
public Texture typ11;
public Texture typ12;
public Texture typ13;
public Transform cube1;
public Transform cube2;
public Transform cube3;
public Transform cube4;
public Transform cube5;
public Transform cube6;
public Transform cube7;
public Transform cube8;
public Transform cube9;
public Transform cube10;
public Transform cube11;
public Transform cube12;
public Transform cube13;
//privates
private toucher TOucher;
private webrequest WEbrequest;
private bool cube_active=false;
private GameObject active_cube;
private bool new_cube_get_placed;
private Transform new_cube_typ;
private bool cube_selection_is_open = false;
private bool delete_popup_active = false;
void Start(){
//This function get called when the game starts,
//here it maps the external scripts
TOucher = this.gameObject.GetComponent<toucher>();
WEbrequest = this.gameObject.GetComponent<webrequest>();
}
void OnGUI(){
//Read valies from other files
cube_active= TOucher.cube_active;
active_cube= TOucher.active_cube;
new_cube_typ = TOucher.new_cube_typ;
new_cube_get_placed = TOucher.new_cube_get_placed;
//GUI Creation
if (cube_selection_is_open==false){
//Cube selection menu is closed
//Display only one button
if(GUI.Button(new Rect(Screen.width-170,20,150,50), "Wurfel hinzufugen", selection_button)) {
cube_selection_is_open=true;
}
}else{
//Display Cube selection
//draw background
GUI.Box(new Rect(0,0,100,Screen.height), "", background_style);
GUI.Box(new Rect(Screen.width-100, 0, Screen.width-100, Screen.height), "", background_style);
//close button
if(GUI.Button(new Rect(Screen.width-30,0,30,30), "X", selection_button)) {
cube_selection_is_open=false;
}
//cubes button
// Left side
GUILayout.BeginArea (new Rect (0,0,100,Screen.height));
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
if (GUILayout.RepeatButton(typ1, cube_style)) {
new_cube_typ=cube1;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ2, cube_style)) {
new_cube_typ=cube2;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ3, cube_style)) {
new_cube_typ=cube3;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ4, cube_style)) {
new_cube_typ=cube4;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ5, cube_style)) {
new_cube_typ=cube5;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ6, cube_style)) {
new_cube_typ=cube6;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ7, cube_style)) {
new_cube_typ=cube7;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ8, cube_style)) {
new_cube_typ=cube8;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ9, cube_style)) {
new_cube_typ=cube9;
new_cube_get_placed=true;
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.EndArea();
// right side
GUILayout.BeginArea (new Rect (Screen.width-100,0,100,Screen.height));
GUILayout.BeginHorizontal();
GUILayout.BeginVertical();
if (GUILayout.RepeatButton(typ10, cube_style)) {
new_cube_typ=cube10;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ11, cube_style)) {
new_cube_typ=cube11;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ12, cube_style)) {
new_cube_typ=cube12;
new_cube_get_placed=true;
}
if (GUILayout.RepeatButton(typ13, cube_style)) {
new_cube_typ=cube13;
new_cube_get_placed=true;
}
if(GUILayout.Button("Send \n cubes")) {
WEbrequest.send_cubes();
}
if(GUILayout.Button("Clear \n all")) {
delete_popup_active = true;
TOucher.popup_opened = true;
TOucher.deselct_active_cube();
TOucher.active_cube=null;
TOucher.cube_active=false;
}
if(GUILayout.Button("Build \n Lager")) {
WEbrequest.build_bahn(0);
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.EndArea();
//Display used cubes
GUI.Box(new Rect(Screen.width/2-50,10,100,20), TOucher.c_ammount_of_cubes+" / "+TOucher.ammount_of_cubes+" Cubes");
//Popups ---
if (TOucher.popup_opened){
//Send cubes
// Are shure you delete?
if (delete_popup_active){
GUI.Box(new Rect(200,200,Screen.width-400,Screen.height-400), "Are you sure, you want to delete all cubes?", popup_style);
if(GUI.Button(new Rect((Screen.width/2)+10,Screen.height/2,200,50), "Yes, do the madness")) {
TOucher.clear_stage();
TOucher.popup_opened = false;
delete_popup_active = false;
}
if(GUI.Button(new Rect((Screen.width/2)-210,Screen.height/2,200,50), "Cancel")) {
TOucher.popup_opened = false;
delete_popup_active = false;
}
}
}
}
//Additional Buttons (only visible when some cube is active / selected)
if (cube_active & (active_cube!=null)){
float x = camera.WorldToScreenPoint(active_cube.transform.position).x;
float y = Screen.height-camera.WorldToScreenPoint(active_cube.transform.position).y;
if(GUI.Button(new Rect(x-15,y-50,30,30), "X")) {
if (active_cube!=null){
TOucher.remove_cube();
}
}
if(GUI.Button(new Rect(x,y,50,30), "->")) {
active_cube.transform.Rotate(Vector3.up * -90);
}
if(GUI.Button(new Rect(x-50,y,50,30), "<-")) {
active_cube.transform.Rotate(Vector3.up * +90);
}
}
//Set external variables
TOucher.cube_selection_is_open=cube_selection_is_open;
TOucher.new_cube_typ=new_cube_typ;
TOucher.new_cube_get_placed=new_cube_get_placed;
}
}