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(); } }
相关文章推荐
- Unity3D 性能优化
- 关于Unity3D打包Android时,Icon模糊的解决方案
- Unity3D协同程序(Coroutine)
- unity 录音, 压缩, 保存, 读取, 实时检测音量
- Unity高像素截图
- Unity高像素截图
- Php中 检查客户端是否来自于Unity
- HoloLens开发手记 - Unity之摄像头篇
- Unity 小案例 加载新场景时数据持久化简单存储
- 编译 unity3d 的示例代码过程
- Unity3D开发之游戏兑换码的分析设计以及生成
- unity, SerializedObject.FindProperty不要写在Editor的OnEnable里,要写在OnInspectorGUI里
- Unity3D/Plugins实现IOS设备二维码扫描功能
- Unity 射线检测碰撞
- unity里面动态的替换shader
- 原生IOS应用(Swift)反复打开关闭Unity View
- Unity3d Android SDK接入解析(二)Unity3d Android SDK的设计与两种接入方式
- Unity手游代码更新策略
- Unity3D+moba+技能指示器(二)
- Unity Shaders and Effects Cookbook (7-2) Surface Shader 中实现 顶点动画