|
@@ -13,7 +13,7 @@ |
13 |
13 |
|
private float shapeSize = 20.0f; |
14 |
14 |
|
private float shapeBorder = 3.0f; |
15 |
15 |
|
|
16 |
|
- |
private Transform spaceShip; |
|
16 |
+ |
private Transform _spaceShip; |
17 |
17 |
|
private Transform _transform; |
18 |
18 |
|
|
19 |
19 |
|
void Start() |
|
@@ -28,12 +28,16 @@ |
28 |
28 |
|
rectMat.hideFlags = HideFlags.HideAndDontSave; |
29 |
29 |
|
rectMat.shader.hideFlags = HideFlags.HideAndDontSave; |
30 |
30 |
|
|
31 |
|
- |
spaceShip = GameManager.Instance.spaceShip; |
|
31 |
+ |
_spaceShip = GameManager.Instance.spaceShip; |
32 |
32 |
|
_transform = transform; |
33 |
33 |
|
} |
34 |
34 |
|
|
35 |
35 |
|
void OnGUI() |
36 |
36 |
|
{ |
|
37 |
+ |
rectMat.SetPass(0); |
|
38 |
+ |
|
|
39 |
+ |
DrawRadarPoint(_transform, rectColor); |
|
40 |
+ |
|
37 |
41 |
|
if(start==null|end==null) |
38 |
42 |
|
{ |
39 |
43 |
|
return; |
|
@@ -48,28 +52,67 @@ |
48 |
52 |
|
Draw(cen); |
49 |
53 |
|
} |
50 |
54 |
|
} |
|
55 |
+ |
|
|
56 |
+ |
|
|
57 |
+ |
} |
|
58 |
+ |
|
|
59 |
+ |
void DrawRadarPoint(Transform ufo, Color col) |
|
60 |
+ |
{ |
|
61 |
+ |
Vector3 relative = _spaceShip.transform.InverseTransformPoint(ufo.position); |
|
62 |
+ |
|
|
63 |
+ |
float distance = Mathf.Sqrt( relative.magnitude / 3.0f ); |
|
64 |
+ |
|
|
65 |
+ |
if (distance > 45.0f) { |
|
66 |
+ |
return; |
|
67 |
+ |
} |
|
68 |
+ |
|
|
69 |
+ |
float angle = Mathf.Atan2(relative.x, relative.z) - 90.0f * Mathf.Deg2Rad; |
|
70 |
+ |
|
|
71 |
+ |
Vector2 D = new Vector2( Mathf.Cos(angle), Mathf.Sin(angle) ); |
|
72 |
+ |
|
|
73 |
+ |
D *= distance; |
|
74 |
+ |
|
|
75 |
+ |
D.x += Screen.width-150; |
|
76 |
+ |
D.y += Screen.height-50; |
|
77 |
+ |
|
|
78 |
+ |
Vector2 dir = new Vector2(0.0f,1.5f); |
|
79 |
+ |
Vector2 right = new Vector2(1.5f,0.0f); |
|
80 |
+ |
Vector2 A = D + dir * 2.0f; |
|
81 |
+ |
Vector2 B = D + right; |
|
82 |
+ |
Vector2 C = D - right; |
|
83 |
+ |
|
|
84 |
+ |
GL.Color(col); |
|
85 |
+ |
|
|
86 |
+ |
GL.Begin(GL.TRIANGLES); |
|
87 |
+ |
GL.Vertex3(A.x, A.y, 0); |
|
88 |
+ |
GL.Vertex3(C.x, C.y, 0); |
|
89 |
+ |
GL.Vertex3(B.x, B.y, 0); |
|
90 |
+ |
GL.End(); |
51 |
91 |
|
} |
52 |
92 |
|
|
53 |
93 |
|
//渲染2D框 |
54 |
94 |
|
void Draw(Vector3 cen) |
55 |
95 |
|
{ |
56 |
|
- |
rectMat.SetPass(0); |
|
96 |
+ |
|
57 |
97 |
|
|
58 |
98 |
|
GL.PushMatrix();//保存摄像机变换矩阵 |
59 |
|
- |
GL.LoadPixelMatrix();//设置用屏幕坐标绘图 |
|
99 |
+ |
try { |
|
100 |
+ |
GL.LoadPixelMatrix();//设置用屏幕坐标绘图 |
60 |
101 |
|
|
61 |
|
- |
// check if OutOfScreen |
62 |
|
- |
if ((cen.x < 0) || (cen.x > Screen.width) || (cen.y < 0) || (cen.y > Screen.height)) { |
63 |
|
- |
Vector2 screenCenter = new Vector2(Screen.width/2, Screen.height/2); |
64 |
|
- |
Vector2 dir = new Vector2(cen.x-screenCenter.x, cen.y-screenCenter.y); |
65 |
|
- |
dir.Normalize(); |
66 |
|
- |
cen = polarProject(screenCenter, dir, shapeSize); |
67 |
|
- |
DrawArrow(cen, dir, shapeSize, rectColor, shapeBorder); |
68 |
|
- |
} else { |
69 |
|
- |
DrawFrame(cen, shapeSize, rectColor, shapeBorder); |
|
102 |
+ |
// check if OutOfScreen |
|
103 |
+ |
if ((cen.x < 0) || (cen.x > Screen.width) || (cen.y < 0) || (cen.y > Screen.height)) { |
|
104 |
+ |
Vector2 screenCenter = new Vector2(Screen.width/2, Screen.height/2); |
|
105 |
+ |
Vector2 dir = new Vector2(cen.x-screenCenter.x, cen.y-screenCenter.y); |
|
106 |
+ |
dir.Normalize(); |
|
107 |
+ |
cen = polarProject(screenCenter, dir, shapeSize); |
|
108 |
+ |
DrawArrow(cen, dir, shapeSize, rectColor, shapeBorder); |
|
109 |
+ |
} else { |
|
110 |
+ |
DrawFrame(cen, shapeSize, rectColor, shapeBorder); |
|
111 |
+ |
} |
|
112 |
+ |
} finally { |
|
113 |
+ |
GL.PopMatrix();//还原 |
70 |
114 |
|
} |
71 |
|
- |
|
72 |
|
- |
GL.PopMatrix();//还原 |
|
115 |
+ |
|
73 |
116 |
|
if ((cen.y-shapeSize)<=0) { |
74 |
117 |
|
DrawDistance(cen.x, cen.y+shapeSize, textColor); |
75 |
118 |
|
} else { |
|
@@ -170,9 +213,9 @@ |
170 |
213 |
|
|
171 |
214 |
|
void DrawDistance(float x, float y,Color col) |
172 |
215 |
|
{ |
173 |
|
- |
if(spaceShip==null) return; |
|
216 |
+ |
if(_spaceShip==null) return; |
174 |
217 |
|
|
175 |
|
- |
float tmp = Vector3.Distance(_transform.position,spaceShip.position); |
|
218 |
+ |
float tmp = Vector3.Distance(_transform.position,_spaceShip.position); |
176 |
219 |
|
int dis = (int)tmp; |
177 |
220 |
|
string str = dis+"km"; |
178 |
221 |
|
GUI.skin.label.normal.textColor=col; |