unity---GL实现案例
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实现案例的更多相关文章
- 转 Unity企业级支持案例与分析
Unity大中华区技术支持总监张黎明以“Unity企业级支持案例与分析”为主题进行了分享. 以下为演讲实录: 张黎明:非常感谢大家来参加今年的Unite,其实我现在看到有的朋友已经不是第一次来参加Un ...
- unite2017《Unity企业级支持案例与分析》
在今天举办的Unite2017开发者大会上,Unity大中华区技术支持总监张黎明以"Unity企业级支持案例与分析"为主题进行了分享. 以下为演讲实录: 张黎明:非常感谢大家来参加 ...
- 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 ...
- Unity Dotween官方案例学习
本文只涉及一些案例,具体查看 DoTween 官方文档. 一. Basics public class Basics : MonoBehaviour { public Transform redCub ...
- Unity XLua 官方案例学习
1. Helloworld using UnityEngine; using XLua; public class Helloworld : MonoBehaviour { // Use this f ...
- Unity GL 画圆
Unity下GL没有画圆的函数,只能自己来了. 如果能帮到大家,我也很高兴. 虽然没有画圆的函数,但是能画直线,利用这一点,配合微积分什么的,就可以画出来了.反正就是花很多连在一起的直线,每条直线足够 ...
- Unity GL画折线
新建一个脚本,这个物体得挂在有摄像机组件的物体上才能生效 OnPostRender() 这个函数才会被自动调用(类似生命周期自动调用) 然后就可以代码画线了,原理是openGL的画线 using Un ...
- unity gl 画线
using UnityEngine; using System.Collections; public class TGLLine : MonoBehaviour { private static M ...
- Unity EasyTouch官方案例学习
一.代码检测手势事件 1. EasyTouch4.x 写法 首先要手动在 Hierarchy 窗口添加 EasyTouch 物体,以触摸(Touch)手势为例,代码如下: using UnityEng ...
- Unity设计模式+Java设计模式,讲解+案例+PPT,一次性学会设计模式,拥抱高薪!
一个程序员对设计模式的理解:“不懂”为什么要把很简单的东西搞得那么复杂.后来随着软件开发经验的增加才开始明白我所看到的“复杂”恰恰就是设计模式的精髓所在,我所理解的“简单”就是一把钥匙开一把锁的模式, ...
随机推荐
- Python使用函数实现杨辉三角
运行效果: 可在函数中指定阶层数,输出对应的杨辉三角 源代码如下: 1 # -*-coding:utf-8 -*- 2 ''' 3 chapter4_do.py 4 函数yanghui(n)用于输出n ...
- SpringMVC的数据响应方式
1.页面跳转 *直接返回字符串 *通过ModelAndView对象返回 2.回写数据 *直接返回字符串 *返回对象或集合
- allure用法(一)-配置信息及基本用法
allure是一个轻量级的,灵活的,支持多语言的测试报告工具 优点: 可以为dev/qa 提供 详尽的测试报告.测试步骤.日志 可以为管理层提供更好的统计报告 Java语言开发的 可以集成到jenki ...
- Python学习阵痛期
Python和之前学习的Java语法上有较大的区别,例如Java中for循环常使用++自增符,在Python中是没有++的. 因为Python中整型.字符型等都是不可变的,一改变值就重新分配了新的内存 ...
- 新手小白入门C语言第二章:基本语法
1. 语句 C 语言的代码由一行行语句(statement)组成.语句就是程序执行的一个操作命令.C 语言规定,语句必须使用分号结尾,除非有明确规定可以不写分号. 如: int x = 1; 这就是一 ...
- jsp第一周作业
环境搭建,运行出来一个JSP页面,显式hello 英文字母表 <%@ page language="java" import="java.util.*" ...
- Ubuntu 下 firebird 数据库的安装和配置
Ubuntu 下 firebird 数据库的安装和配置 1.简介 本文主要是 Ubuntu 下 firebird 数据库的安装和目录迁移,同样适用于 Debian 系统:Ubuntu 20.0.4 f ...
- 我用 CSS3 实现了一个超炫的 3D 加载动画
今天给大家带来一个非常炫酷的CSS3加载Loading动画,它的特别之处在于,整个Loading动画呈现出了3D的视觉效果.这个Loading加载动画由12个3D圆柱体围成一个椭圆形,同时这12个圆柱 ...
- 【openstack】红帽公开课笔记内容openstack
overcloud节点自省失败(introspection) 节点自省--获取overcloud
- MySQL备份迁移之mydumper
简介 mydumper 是一款开源的 MySQL 逻辑备份工具,主要由 C 语言编写.与 MySQL 自带的 mysqldump 类似,但是 mydumper 更快更高效. mydumper 的一些优 ...