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();
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步