-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLTRect.cs
281 lines (236 loc) · 4.61 KB
/
LTRect.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
using System;
using UnityEngine;
[Serializable]
public class LTRect
{
public Rect _rect;
public float alpha = 1f;
public float rotation;
public Vector2 pivot;
public Vector2 margin;
public Rect relativeRect = new Rect(0f, 0f, float.PositiveInfinity, float.PositiveInfinity);
public bool rotateEnabled;
[HideInInspector]
public bool rotateFinished;
public bool alphaEnabled;
public string labelStr;
public LTGUI.Element_Type type;
public GUIStyle style;
public bool useColor;
public Color color = Color.white;
public bool fontScaleToFit;
public bool useSimpleScale;
public bool sizeByHeight;
public Texture texture;
private int _id = -1;
[HideInInspector]
public int counter;
public static bool colorTouched;
public bool hasInitiliazed => _id != -1;
public int id => _id | (counter << 16);
public float x
{
get
{
return _rect.x;
}
set
{
_rect.x = value;
}
}
public float y
{
get
{
return _rect.y;
}
set
{
_rect.y = value;
}
}
public float width
{
get
{
return _rect.width;
}
set
{
_rect.width = value;
}
}
public float height
{
get
{
return _rect.height;
}
set
{
_rect.height = value;
}
}
public Rect rect
{
get
{
if (colorTouched)
{
colorTouched = false;
Color color = GUI.color;
float r = color.r;
Color color2 = GUI.color;
float g = color2.g;
Color color3 = GUI.color;
GUI.color = new Color(r, g, color3.b, 1f);
}
if (rotateEnabled)
{
if (rotateFinished)
{
rotateFinished = false;
rotateEnabled = false;
pivot = Vector2.zero;
}
else
{
GUIUtility.RotateAroundPivot(rotation, pivot);
}
}
if (alphaEnabled)
{
Color color4 = GUI.color;
float r2 = color4.r;
Color color5 = GUI.color;
float g2 = color5.g;
Color color6 = GUI.color;
GUI.color = new Color(r2, g2, color6.b, alpha);
colorTouched = true;
}
if (fontScaleToFit)
{
if (useSimpleScale)
{
style.fontSize = (int)(_rect.height * relativeRect.height);
}
else
{
style.fontSize = (int)_rect.height;
}
}
return _rect;
}
set
{
_rect = value;
}
}
public LTRect()
{
reset();
rotateEnabled = (alphaEnabled = true);
_rect = new Rect(0f, 0f, 1f, 1f);
}
public LTRect(Rect rect)
{
_rect = rect;
reset();
}
public LTRect(float x, float y, float width, float height)
{
_rect = new Rect(x, y, width, height);
alpha = 1f;
rotation = 0f;
rotateEnabled = (alphaEnabled = false);
}
public LTRect(float x, float y, float width, float height, float alpha)
{
_rect = new Rect(x, y, width, height);
this.alpha = alpha;
rotation = 0f;
rotateEnabled = (alphaEnabled = false);
}
public LTRect(float x, float y, float width, float height, float alpha, float rotation)
{
_rect = new Rect(x, y, width, height);
this.alpha = alpha;
this.rotation = rotation;
rotateEnabled = (alphaEnabled = false);
if (rotation != 0f)
{
rotateEnabled = true;
resetForRotation();
}
}
public void setId(int id, int counter)
{
_id = id;
this.counter = counter;
}
public void reset()
{
alpha = 1f;
rotation = 0f;
rotateEnabled = (alphaEnabled = false);
margin = Vector2.zero;
sizeByHeight = false;
useColor = false;
}
public void resetForRotation()
{
Vector3 vector = new Vector3(GUI.matrix[0, 0], GUI.matrix[1, 1], GUI.matrix[2, 2]);
if (pivot == Vector2.zero)
{
pivot = new Vector2((_rect.x + _rect.width * 0.5f) * vector.x + GUI.matrix[0, 3], (_rect.y + _rect.height * 0.5f) * vector.y + GUI.matrix[1, 3]);
}
}
public LTRect setStyle(GUIStyle style)
{
this.style = style;
return this;
}
public LTRect setFontScaleToFit(bool fontScaleToFit)
{
this.fontScaleToFit = fontScaleToFit;
return this;
}
public LTRect setColor(Color color)
{
this.color = color;
useColor = true;
return this;
}
public LTRect setAlpha(float alpha)
{
this.alpha = alpha;
return this;
}
public LTRect setLabel(string str)
{
labelStr = str;
return this;
}
public LTRect setUseSimpleScale(bool useSimpleScale, Rect relativeRect)
{
this.useSimpleScale = useSimpleScale;
this.relativeRect = relativeRect;
return this;
}
public LTRect setUseSimpleScale(bool useSimpleScale)
{
this.useSimpleScale = useSimpleScale;
relativeRect = new Rect(0f, 0f, (float)Screen.width, (float)Screen.height);
return this;
}
public LTRect setSizeByHeight(bool sizeByHeight)
{
this.sizeByHeight = sizeByHeight;
return this;
}
public override string ToString()
{
return "x:" + _rect.x + " y:" + _rect.y + " width:" + _rect.width + " height:" + _rect.height;
}
}