新建一个脚本,这个物体得挂在有摄像机组件的物体上才能生效

OnPostRender() 这个函数才会被自动调用(类似生命周期自动调用)

然后就可以代码画线了,原理是openGL的画线

using UnityEngine;
using System.Collections;
using System.Collections.Generic; /// <summary>
/// GL画图
/// </summary>
public class GLDraw : UnityNormalSingleton<GLDraw> { public Transform p1;
public Transform p2;
private List<Vector2> pointList;
private bool isOpen; private Material mat;
private Shader shader; private void Start()
{
pointList = new List<Vector2>();
shader = Shader.Find("Unlit/Color");
mat = new Material(shader);
mat.SetColor("Main Color", Color.black);
} public void DrawLine(List<object> list)
{
pointList.Clear();
for (int i = ; i < list.Count; i++)
{
Vector2 screenPos = (Vector2)list[i];
pointList.Add(new Vector2(screenPos.x, Screen.height - screenPos.y));
}
} public void ShowLine(bool b)
{
isOpen = b;
} void OnPostRender()
{
if (!isOpen)
{
return;
} //mat = new Material(Shader.Find("Unlit/Color"));
//Debug.Log("调用");
//if (!mat)
//{
// Debug.LogError("Please Assign a material on the inspector");
// return;
//}
GL.PushMatrix(); //保存当前Matirx
mat.SetPass(); //刷新当前材质
GL.LoadPixelMatrix();//设置pixelMatrix
GL.Color(Color.yellow);
GL.Begin(GL.LINES); //画2次,奇偶数画连续折线法
for (int i = ; i < pointList.Count; i++)
{
GL.Vertex3(pointList[i].x, pointList[i].y, );
}
for (int i = ; i < pointList.Count; i++)
{
GL.Vertex3(pointList[i].x, pointList[i].y, );
}

     //单次画线发
//GL.Vertex3(0, 0, 0);//GL.Vertex3(Screen.width, Screen.height, 0);

     //固定2点画
//GL.Vertex3(p1.position.x, p1.position.y, 0);
//GL.Vertex3(p2.position.x, p2.position.y, 0);
GL.End();
GL.PopMatrix();//读取之前的Matrix
}
}

Unity GL画折线的更多相关文章

  1. Unity GL 画圆

    Unity下GL没有画圆的函数,只能自己来了. 如果能帮到大家,我也很高兴. 虽然没有画圆的函数,但是能画直线,利用这一点,配合微积分什么的,就可以画出来了.反正就是花很多连在一起的直线,每条直线足够 ...

  2. unity gl 画线

    using UnityEngine; using System.Collections; public class TGLLine : MonoBehaviour { private static M ...

  3. python中matplotlib画折线图实例(坐标轴数字、字符串混搭及标题中文显示)

    最近在用python中的matplotlib画折线图,遇到了坐标轴 "数字+刻度" 混合显示.标题中文显示.批量处理等诸多问题.通过学习解决了,来记录下.如有错误或不足之处,望请指 ...

  4. SAS 画折线图PROC GPLOT

    虽然最后做成PPT里的图表会被要求用EXCEL画,但当我们只是在分析的过程中,想看看数据的走势,直接在SAS里画会比EXCEL画便捷的多. 修改起来也会更加的简单,,不用不断的修改程序然后刷新EXCE ...

  5. echarts入门基础,画折线图

    注意:一定要自己引入echarts库 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  6. Matplotlib学习---用matplotlib画折线图(line chart)

    这里利用Jake Vanderplas所著的<Python数据科学手册>一书中的数据,学习画图. 数据地址:https://raw.githubusercontent.com/jakevd ...

  7. echars画折线图的一种数据处理方式

    echars画折线图的一种数据处理方式 <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...

  8. python的turtle模块画折线图

    代码如下: import turtle yValues = [10.0,7.4,6.4,5.3,4.4,3.7,2.6] def main(): t = turtle.Turtle() t.hidet ...

  9. 使用OpenCV画折线图

    使用OpenCV画直方图是一件轻松的事情,画折线图就没有那么Easy了,还是使用一个库吧: GraphUtils 源代码添加入工程 原文链接:http://www.360doc.com/content ...

随机推荐

  1. Delphi 中调用JS文件中的方法

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  2. 20145233《网络对抗》Exp8 Web基础

    20145233<网络对抗>Exp8 Web基础 实验问题思考 什么是表单? 表单在网页中主要负责数据采集功能 一个表单有三个基本组成部分: 表单标签 表单域:包含了文本框.密码框.隐藏域 ...

  3. redis----内部数据结构学习

    整数集合 1.应用 用于有序.无重复的保存多个整数值 自动选择该用什么长度的整数类型保存数据

  4. 查看iptables状态-重启

    iptables 所在目录 /etc/sysconfig/iptables service iptables status 查看iptables状态 service iptables restart ...

  5. SQL Server 隐式转换引发的死锁

    在SQL Server的应用开发过程(尤其是二次开发)中可能由于开发人员对表的结构不够了解,造成开发过程中使用了不合理的方式造成数据库引擎未按预定执行,以致影响业务.这是非常值得注意的.这次为大家介绍 ...

  6. Java中获取运行代码的类名、方法名

    以下是案例,已运行通过 package com.hdys; /* * 1.获取当前运行代码的类名,方法名,主要是通过java.lang.StackTraceElement类 * * 2. * [1]获 ...

  7. kvm虚拟机时间配置

    注:在虚拟化环境中,虚拟机在长时间运行过程中,时间会变慢,通常的作法是配置ntpdate定时与时间服务器进行时间同步的计划任务. KVM虚拟机默认采用utc时间,需要专门修改,以及考虑kvm时间同步问 ...

  8. c#中的classes和objects一些知识【1】

    首先我们需要知道面向对象语言(Object-oriented language)的三大特点:封装(Encapulation),继承(Inheritance),多态(Polymorphism). 引言: ...

  9. Flink学习笔记:Time的故事

    本文为<Flink大数据项目实战>学习笔记,想通过视频系统学习Flink这个最火爆的大数据计算框架的同学,推荐学习课程: Flink大数据项目实战:http://t.cn/EJtKhaz ...

  10. Python3之 contextlib

    Python中当我们们打开文本时,通常会是用with语句,with语句允许我们非常方便的使用资源,而不必担心资源没有关闭. with open('/path/filename', 'r') as f: ...