GL

C#实现

不管是画任何东西都需要Begin()和End()函数;

画线

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class GL_Line : MonoBehaviour
{
// Start is called before the first frame update
// public Material material;
void OnPostRender()
{
// if(!material){
// Debug.LogError("请给材质赋值??");
// return;
// }
// material.SetPass(0);
GL.LoadOrtho();
GL.Begin(GL.LINES); GL.Color(new Color(255,0,0));//线段颜色
GL.Vertex(new Vector3(0,0,0));
GL.Vertex(new Vector3(100f/Screen.width,100f/Screen.height,0)); GL.End();
}
}

画曲线

根据鼠标位置实时画线

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class GL_Curve : MonoBehaviour
{
// Start is called before the first frame update
List<Vector3> lineInfo;
void Start(){
lineInfo=new List<Vector3>();
}
void Update() {
// if(Input.GetMouseButton(0)) // 添加这句话可以控制开始 结束
lineInfo.Add(new Vector3(Input.mousePosition.x/Screen.width,Input.mousePosition.y/Screen.height,0));
}
void OnPostRender()
{
GL.LoadOrtho();
GL.Begin(GL.LINES);
GL.Color(new Color(255,0,0));
for(int i = 0;i<lineInfo.Count-1;i++){
GL.Vertex(lineInfo[i]);
GL.Vertex(lineInfo[i+1]);
} //GL.Vertex(new Vector3(100,100,0)); GL.End();
} }

画正方体

需要准备四个点,位置都是浮点数

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class GL_Quads : MonoBehaviour
{
// Start is called before the first frame update
private void OnPostRender() {
GL.LoadOrtho();
GL.Begin(GL.QUADS);
GL.Color(new Color(255,0,0)); GL.Vertex(new Vector3(0,0,0));
GL.Vertex(new Vector3(300f/Screen.width,0,0));
GL.Vertex(new Vector3(300f/Screen.width,300f/Screen.height,0));
GL.Vertex(new Vector3(0,300f/Screen.height,0)); GL.End();
}
}

LineRenderer画线

推荐这篇博客 LineRenderer画线

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class GL_Line1 : MonoBehaviour
{
// Start is called before the first frame update
public LineRenderer lineRenderer; // Update is called once per frame
void Start()
{
lineRenderer.positionCount=4;
lineRenderer.startWidth=0.1f;
lineRenderer.endWidth=0.1f; }
Vector3 v0=new Vector3(1f,0,0);
Vector3 v1=new Vector3(2f,0,0);
Vector3 v2=new Vector3(3f,0,0);
Vector3 v3=new Vector3(4f,0,0);
private void Update() {
lineRenderer.SetPosition(0,v0);
lineRenderer.SetPosition(1,v1);
lineRenderer.SetPosition(2,v2);
lineRenderer.SetPosition(3,v3);
}
}

unity---GL实现案例的更多相关文章

  1. 转 Unity企业级支持案例与分析

    Unity大中华区技术支持总监张黎明以“Unity企业级支持案例与分析”为主题进行了分享. 以下为演讲实录: 张黎明:非常感谢大家来参加今年的Unite,其实我现在看到有的朋友已经不是第一次来参加Un ...

  2. unite2017《Unity企业级支持案例与分析》

    在今天举办的Unite2017开发者大会上,Unity大中华区技术支持总监张黎明以"Unity企业级支持案例与分析"为主题进行了分享. 以下为演讲实录: 张黎明:非常感谢大家来参加 ...

  3. unity, GL.TexCoord or GL.Color must put before GL.Vertex!!!

    GL.Begin(GL.QUADS);                //in unity, should use left hand rule        //RU        GL.TexCo ...

  4. Unity Dotween官方案例学习

    本文只涉及一些案例,具体查看 DoTween 官方文档. 一. Basics public class Basics : MonoBehaviour { public Transform redCub ...

  5. Unity XLua 官方案例学习

    1. Helloworld using UnityEngine; using XLua; public class Helloworld : MonoBehaviour { // Use this f ...

  6. Unity GL 画圆

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

  7. Unity GL画折线

    新建一个脚本,这个物体得挂在有摄像机组件的物体上才能生效 OnPostRender() 这个函数才会被自动调用(类似生命周期自动调用) 然后就可以代码画线了,原理是openGL的画线 using Un ...

  8. unity gl 画线

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

  9. Unity EasyTouch官方案例学习

    一.代码检测手势事件 1. EasyTouch4.x 写法 首先要手动在 Hierarchy 窗口添加 EasyTouch 物体,以触摸(Touch)手势为例,代码如下: using UnityEng ...

  10. Unity设计模式+Java设计模式,讲解+案例+PPT,一次性学会设计模式,拥抱高薪!

    一个程序员对设计模式的理解:“不懂”为什么要把很简单的东西搞得那么复杂.后来随着软件开发经验的增加才开始明白我所看到的“复杂”恰恰就是设计模式的精髓所在,我所理解的“简单”就是一把钥匙开一把锁的模式, ...

随机推荐

  1. 六、cadence叠层和布线前规则设置详细步骤

    一.叠层设置 1.颜色设置 2.层叠设置setup-cross section,如下图: 3.布线规则设置 a>线宽设置 b>添加差分对logic-Assign Differenital ...

  2. Citus 分布式 PostgreSQL 集群 - SQL Reference(SQL支持和变通方案)

    由于 Citus 通过扩展 PostgreSQL 提供分布式功能,因此它与 PostgreSQL 结构兼容.这意味着用户可以使用丰富且可扩展的 PostgreSQL 生态系统附带的工具和功能来处理使用 ...

  3. RStudio中文乱码

    解决办法一: 1.设置RStudio文本显示的默认编码:RStudio菜单栏的Tools -> Global Options 2.code-->saving-->default te ...

  4. python 反序列化

    Python-反序列化函数使用 pickle.dump(obj, file) : 将对象序列化后保存到文件 pickle.load(file) : 读取文件, 将文件中的序列化内容反序列化为对象 pi ...

  5. IDEA-2020版本 Gradle项目控制台输出乱码

    点击Help->Edit custom vm options 加入下面这一行 -Dfile.encoding=utf-8 最后当然要重启idea了

  6. Istio实践(1)-环境搭建及应用部署

    1. Istio简介 Istio是最初由IBM,Google和Lyft开发的服务网格的开源实现.它可以透明地分层到分布式应用程序上,并提供服务网格的所有优点,例如流量管理,安全性和可观察性. 它旨在与 ...

  7. 【面试普通人VS高手系列】innoDB如何解决幻读

    前天有个去快手面试的小伙伴私信我,他遇到了这样一个问题: "InnoDB如何解决幻读"? 这个问题确实不是很好回答,在实际应用中,很多同学几乎都不关注数据库的事务隔离性. 所有问题 ...

  8. .NET MAUI发布了期待已久的候选版本(RC1)

    作者:David Ortinau 我们激动地宣布在4/13/2022.NET多平台应用UI (.NET MAUI)发布了候选版本.SDK现在已经集成好了API,可以更新库,并为GA(通用可用性)兼容性 ...

  9. Vue Router的简单了解

    Vue Router Vue Router官方文档 传统Web项目开发往往采用超链接实现页面之间的切换和跳转.Vue开发的是单页面应用(Single Page Application,SPA),不能使 ...

  10. 『现学现忘』Git基础 — 14、Git基础操作的总结与补充

    目录 1.Git本地版本库结构 2.Git常用操作方法 3.补充:添加多个文件到暂存区 4.补充:提交操作未写备注 5.补充:从工作区直接提交到版本库 1.Git本地版本库结构 如下图所示: 工作区( ...