您的位置:首页 > 移动开发 > Unity3D

unity 使用GL画线段

2016-05-12 20:44 423 查看
using UnityEngine;
using System.Collections;

public class TGLLine : MonoBehaviour {

private static Material mat;

void Start () {
CreateLineMaterial();
}

void Update () {

}

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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: