using UnityEngine; using System.Collections; public class TGLLine : MonoBehaviour { private static Material mat; void Start () { CreateLineMaterial(); } void Update () { } //画线框用的mat public static Material CreateLineMaterial(){ mat = 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 }" + "} } }"); mat.hideFlags = HideFlags.HideAndDontSave; mat.shader.hideFlags = HideFlags.HideAndDontSave; //mat.SetPass(0); return mat; } void OnRenderObject() { ShowLine(Color.green); } void ShowLine(Color c,float offsety = 0.2f) { //设置当前的材质 mat.SetPass( 0 ); GL.Begin( GL.LINES ); GL.Color(c); for(int i=0;i<3;i++){ Vector3 p0; p0.x=0f; p0.z=0f; p0.y=0+offsety; GL.Vertex(p0); Vector3 p; p.x=9f; p.z=0f+i*2; p.y=offsety; GL.Vertex(p); } GL.End(); } }