Unity之屏幕画线
using UnityEngine;
using System.Collections;
public class DrawRectangle : MonoBehaviour {
public Color rectColor = Color.green;
private Material rectMat = null;//画线的材质 不设定系统会用当前材质画线 结果不可控
// Use this for initialization
void Start () {
rectMat = 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 }" +
"} } }" );//生成画线的材质
rectMat.hideFlags = HideFlags.HideAndDontSave;
rectMat.shader.hideFlags = HideFlags.HideAndDontSave;
}
void Update () {
}
void OnPostRender() {//画线这种操作推荐在OnPostRender()里进行 而不是直接放在Update,所以需要标志来开启
Rect rect0 = new Rect(0,0,0,0);
drawRect(rect0);
}
void drawRect(Rect rect0){
if (! rectMat)
return;
GL.PushMatrix();//保存摄像机变换矩阵
rectMat.SetPass( 0 );
GL.LoadPixelMatrix();//设置用屏幕坐标绘图
// GL.Begin(GL.QUADS);
// GL.Color( new Color(rectColor.r,rectColor.g,rectColor.b,0.1f) );//设置颜色和透明度,方框内部透明
// GL.Vertex3( 0,0,0);
// GL.Vertex3( Screen.width/2,0,0);
// GL.Vertex3( Screen.width/2,Screen.height/2,0 );
// GL.Vertex3( 0,Screen.height/2,0 );
// GL.End();
float startX = rect0.x;
float startY = rect0.y;
float endX = rect0.xMax;
float endY = rect0.yMax;
GL.Begin(GL.LINES);
GL.Color(rectColor);//设置方框的边框颜色 边框不透明
GL.Vertex3( startX,startY,0);
GL.Vertex3( endX,startY,0);
GL.Vertex3( endX,startY,0);
GL.Vertex3( endX,endY,0 );
GL.Vertex3( endX,endY,0 );
GL.Vertex3( startX,endY,0 );
GL.Vertex3( startX,endY,0 );
GL.Vertex3( startX,startY,0);
GL.End();
// GL.Begin(GL.LINES);
// GL.Vertex3(0, 0, 0);
// GL.Vertex3(Screen.width, Screen.height, 0);
// GL.End();
GL.PopMatrix();//恢复摄像机投影矩阵
}
void drawRects(Rect[] rects){
if (! rectMat)
return;
GL.PushMatrix();//保存摄像机变换矩阵
rectMat.SetPass( 0 );
GL.LoadPixelMatrix();//设置用屏幕坐标绘图
// GL.Begin(GL.QUADS);
// GL.Color( new Color(rectColor.r,rectColor.g,rectColor.b,0.1f) );//设置颜色和透明度,方框内部透明
// GL.Vertex3( 0,0,0);
// GL.Vertex3( Screen.width/2,0,0);
// GL.Vertex3( Screen.width/2,Screen.height/2,0 );
// GL.Vertex3( 0,Screen.height/2,0 );
// GL.End();
GL.Begin(GL.LINES);
for(int i = 0 ; i < rects.Length ; i++){
Rect rect0 = rects[i];
//Debug.Log(rect0);
float startX = rect0.x;
float startY = rect0.y;
float endX = rect0.xMax;
float endY = rect0.yMax;
GL.Color(rectColor);//设置方框的边框颜色 边框不透明
GL.Vertex3( startX,startY,0);
GL.Vertex3( endX,startY,0);
GL.Vertex3( endX,startY,0);
GL.Vertex3( endX,endY,0 );
GL.Vertex3( endX,endY,0 );
GL.Vertex3( startX,endY,0 );
GL.Vertex3( startX,endY,0 );
GL.Vertex3( startX,startY,0);
}
GL.End();
// GL.Begin(GL.LINES);
// GL.Vertex3(0, 0, 0);
// GL.Vertex3(Screen.width, Screen.height, 0);
// GL.End();
GL.PopMatrix();//恢复摄像机投影矩阵
}
}
Unity之屏幕画线的更多相关文章
- Unity使用GL画线
脚本需挂在相机上,如果你的脚本,编辑器报错了,Matrix stack full depth reached,加上这个方法试试GL.LoadPixelMatrix(); using System.Co ...
- unity3d之在屏幕上画线
如何在屏幕上画线,简单的代码如下: using UnityEngine; public class Test : MonoBehaviour { void OnGUI() { GL.LoadOrtho ...
- android 屏幕上面画线
作业如下:在android屏幕上面任意画线 package feng.f121.drawline;//本人创建的包名,每人有每人的不同的包 import java.security.PublicKey ...
- Android中Path类的lineTo方法和quadTo方法画线的区别
转载:http://blog.csdn.net/stevenhu_223/article/details/9229337 当我们需要在屏幕上形成画线时,Path类的应用是必不可少的,而Path类的li ...
- Unity3D 画线插件 Vectrosity_Simple2DLine
Vectrosity是一个很方便的画线插件,用它我们可以画出2D,3D,贝塞尔,圆,椭圆等各种线条图案. :链接: http://pan.baidu.com/s/1pJjTFjt 密码: uesn 首 ...
- VC动态轨迹画线
分类: 2.4 线程/图形学2010-04-30 22:14 1878人阅读 评论(0) 收藏 举报 文档null 这是一个绘制直线的简单绘图程序,能过实现动态轨迹画线,在拖动时产生临时线来表示可能画 ...
- android中实现在ImageView上随意画线涂鸦
我实现的思路: 1.继承ImageView类 2.重写onTouchEvent方法,在ACTION_MOVE(即移动时),记录下所经过的点坐标,在ACTION_UP时(即手指离开时,这时一条线已经画完 ...
- Delphi下OpenGL2d绘图(03)-画线
一.前言 画线与画点基本上代码是相同.区别在于glBegin()的参数.绘制的框架代码可以使用 Delphi下OpenGL2d绘图(01)-初始化 中的代码.修改的部份为 Draw 函数的内容. 二. ...
- OpenGL进阶演示样例1——动态画线(虚线、实线、颜色、速度等)
用OpenGL动态绘制线段.事实上非常easy,但到如今为止.网上可參考资料并不多. 于是亲自己主动手写一个函数,方便动态绘制线段.代码例如以下: #include<GL/glu ...
随机推荐
- js中的this和apply
this是js的一个关键字,随着函数使用场合不同,this的值会发生变化.但是总有一个原则,那就是this指的是调用函数的那个对象. 1.纯粹函数调用. function test() { this. ...
- Windows Server Backup 2008 R2 备份Hyper-V
要备份 Hyper-V 虚拟机从父分区在 Windows Server 2008 上使用 Windows 服务器备份,您必须注册 Microsoft Hyper-V VSS 编写器 Windows 服 ...
- hadoop备战:hadoop,hbase兼容版本号汇总
Hbase的安装须要考虑Hadoop的版本号,即兼容性.有不足的希望能指出. 下面考究官网得到的,关于hadoop版本号和hbase版本号可到下面网址中下载:http://mirror.bit.edu ...
- C++ Primer 学习笔记_46_STL实践与分析(20)--容器特有的算法
STL实践与分析 --容器特有的算法 与其它顺序容器所支持的操作相比,标准库为list容器定义了更精细的操作集合,使它不必仅仅依赖于泛型操作.当中非常大的一个原因就是list容器不是依照内存中的顺序进 ...
- 【JS】识别浏览器版本及操作平台
背景: 有这么个需求,需要统计,用户打开网站使用的浏览器,以及操作平台. 实现: 受HTML5Test这个网站的影响,发现它可以实现,获取浏览器以及平台的功能,然后研究代码发现了这个 ...
- centos7.2安装配置
VMware12上安装Centos7,如果电脑是64位,这必须选择64位的centos系统,不然安装完会找不到网卡.安装过程中应当开启网卡选项. 安装完想用ifconfig命令查找IP地址会提示错误: ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...
- Android学习之路
Android基础 整理下个人认为新手们必须要掌握的知识点,顺便也会附带相应觉得不错的讲解博客地址. 两分钟彻底让你明白Android Activity生命周期(图文)! Activity实际开发中使 ...
- JAVA正则表达式语法大全
[正则表达式]文本框输入内容控制 整数或者小数:^[0-9]+\.{0,1}[0-9]{0,2}$ 只能输入数字:"^[0-9]*$". 只能输入n位的数字:"^\d{n ...