public class Test : MonoBehaviour
{
//由于Camera在完成绘制后会清空屏幕,若此前调用GL接口,绘制内容会被清空。通常会在Camera的OnPostRender()或绘制对象的OnRenderXX()中。
private void OnPostRender()
{
//DrawSingleLine();
DrawMutilLine();
//DrawScreenSingleLine();
}
void DrawMutilLine() {
List<Vector3> posList = new List<Vector3>();
posList.Add(new Vector3(0.3f, 0.6f, 0));
posList.Add(new Vector3(1.2f, 1.8f, 0));
posList.Add(new Vector3(0.6f, 2.4f, 0));
posList.Add(new Vector3(1.5f, 2.7f, 0));
if (posList.Count < 2) return;
GL.Begin(GL.LINES);
for (int i = 0; i < posList.Count - 1; i++) {
GL.Vertex(posList[i]);
GL.Vertex(posList[i + 1]);
}
GL.End();
}
void DrawSingleLine() {
Vector3 start = Vector3.zero;
Vector3 end = new Vector3(10, 10, 10);
GL.Begin(GL.LINES);
GL.Color(Color.red);
GL.Vertex(start);
GL.Vertex(end);
GL.End();
}
void DrawScreenSingleLine()
{
Vector3 start = Vector3.zero;
Vector3 end = new Vector3(0.2f, 0.7f, 0);
GL.LoadOrtho(); //屏幕空间,圆心为屏幕左下角,屏幕区域{(0,1), (0,1)}
GL.Begin(GL.LINES);
GL.Color(Color.red);
GL.Vertex(start);
GL.Vertex(end);
GL.End();
}
}
网友评论