Nextrek
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
|
using UnityEngine;
using System.Collections;
public class DrawCross : MonoBehaviour
{
private Transform spaceShip;
public Texture cursor;
private Material rectMat = null;
private Vector2 offset;
void Start()
{
spaceShip = GameManager.Instance.spaceShip;
rectMat = new Material("Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass { " +
" Blend SrcAlpha OneMinusSrcAlpha " +
" ZWrite Off Cull Off Fog { Mode Off } " +
" BindChannels {" +
" Bind \"vertex\", vertex Bind \"color\", color }" +
"} } }");
rectMat.hideFlags = HideFlags.HideAndDontSave;
rectMat.shader.hideFlags = HideFlags.HideAndDontSave;
offset = new Vector2(cursor.width/2,cursor.height/2);
}
void OnGUI()
{
Draw();
/*
Vector2 pos = (Vector2)Input.mousePosition-offset;
pos.x = Mathf.Clamp(pos.x,0,Screen.width);
pos.y = Mathf.Clamp(pos.y,0,Screen.height);
GUI.DrawTexture(new Rect(pos.x,Screen.height-pos.y,cursor.width,cursor.height),cursor);
*/
}
void Draw()
{
if(spaceShip==null)return;
Vector3 cen = spaceShip.position+spaceShip.forward*1000;
cen = Camera.main.WorldToScreenPoint(cen);
//Vector2 cen = new Vector2(Screen.width/2,Screen.height/2);
float len = 10;
rectMat.SetPass(0);
GL.PushMatrix();
try {
GL.LoadPixelMatrix();
GL.Begin(GL.LINES);
GL.Color(Color.white);
GL.Vertex3(cen.x-len,cen.y,0);
GL.Vertex3(cen.x+len,cen.y,0);
GL.End();
GL.Begin(GL.LINES);
GL.Color(Color.white);
GL.Vertex3(cen.x,cen.y-len,0);
GL.Vertex3(cen.x,cen.y+len,0);
GL.End();
} finally {
GL.PopMatrix();
}
}
}
|