유용합니다
ex) 스타크레프트 캐릭터선택 사각형 그리기
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
|
#if Unity_EDITOR
using UnityEditor;
#endif
using UnityEngine;
public static class DrawRectUtils{
static Texture2D _whiteTexture;
public static Texture2D WhiteTexture
{
get
{
if (_whiteTexture == null)
{
_whiteTexture = new Texture2D(1, 1);
_whiteTexture.SetPixel(0, 0, Color.white);
_whiteTexture.Apply();
}
return _whiteTexture;
}
}
public static void DrawScreenRect(Rect rect, Color color)
{
GUI.color = color;
GUI.DrawTexture(rect, WhiteTexture);
GUI.color = Color.white;
}
public static void DrawScreenRectBorder(Rect rect, float thickness, Color color)
{
//top
DrawRectUtils.DrawScreenRect(new Rect(rect.xMin, rect.yMin, rect.width, thickness), color);
//left
DrawRectUtils.DrawScreenRect(new Rect(rect.xMin, rect.yMin, thickness, rect.height), color);
//right
DrawRectUtils.DrawScreenRect(new Rect(rect.xMax - thickness, rect.yMin, thickness, rect.height), color);
//bottom
DrawRectUtils.DrawScreenRect(new Rect(rect.xMin, rect.yMax - thickness, rect.width, thickness), color);
}
public static Rect GetScreenRect(Vector3 screenPosition1, Vector3 screenPosition2)
{
screenPosition1.y = Screen.height - screenPosition1.y;
screenPosition2.y = Screen.height - screenPosition2.y;
var topLeft = Vector3.Min(screenPosition1, screenPosition2);
var bottomRight = Vector3.Max(screenPosition1, screenPosition2);
return Rect.MinMaxRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
}
| cs |
댓글 없음:
댓글 쓰기