unity 异步加载清除3D用GL画的线怎么清除

Unity3D GL方式画线 | Unity3D教程手册
当前位置 :
>> Unity3D GL方式画线
Unity3D GL方式画线
GL方式画线如下图:
相关文章:
Unity3D GL方式画线
把如下脚本放在摄像机上:
using UnityE
using System.C
[RequireComponent(typeof (Camera))]
public class VectorLine : MonoBehaviour
public int numberOfPoints = 2;
public Color lineColor = Color.
public int lineWidth = 3;
public bool drawLines =
private Material lineM
private Vector2[] lineP
void Awake()
lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass {" +
BindChannels { Bind \"Color\",color }" +
Blend SrcAlpha OneMinusSrcAlpha" +
ZWrite Off Cull Off Fog { Mode Off }" +
lineMaterial.hideFlags = HideFlags.HideAndDontS
lineMaterial.shader.hideFlags = HideFlags.HideAndDontS
// Creates a simple two point line
void Start()
linePoints = new Vector2[2];
// Sets line endpoints to center of screen and mouse position
void Update()
linePoints[0] = new Vector2(0.5f, 0.5f);
linePoints[1] = new Vector2(Input.mousePosition.x/Screen.width, Input.mousePosition.y/Screen.height);
void OnPostRender()
if (!drawLines || linePoints == null || linePoints.Length & 2)
float nearClip = cam.nearClipPlane + 0.00001f;
int end = linePoints.Length - 1;
float thisWidth = 1f/Screen.width * lineWidth * 0.5f;
lineMaterial.SetPass(0);
GL.Color(lineColor);
if (lineWidth == 1)
GL.Begin(GL.LINES);
for (int i = 0; i & ++i)
GL.Vertex(cam.ViewportToWorldPoint(new Vector3(linePoints[i].x, linePoints[i].y, nearClip)));
GL.Vertex(cam.ViewportToWorldPoint(new Vector3(linePoints[i+1].x, linePoints[i+1].y, nearClip)));
GL.Begin(GL.QUADS);
for (int i = 0; i & ++i)
Vector3 perpendicular = (new Vector3(linePoints[i+1].y, linePoints[i].x, nearClip) -
new Vector3(linePoints[i].y, linePoints[i+1].x, nearClip)).normalized * thisW
Vector3 v1 = new Vector3(linePoints[i].x, linePoints[i].y, nearClip);
Vector3 v2 = new Vector3(linePoints[i+1].x, linePoints[i+1].y, nearClip);
GL.Vertex(cam.ViewportToWorldPoint(v1 - perpendicular));
GL.Vertex(cam.ViewportToWorldPoint(v1 + perpendicular));
GL.Vertex(cam.ViewportToWorldPoint(v2 + perpendicular));
GL.Vertex(cam.ViewportToWorldPoint(v2 - perpendicular));
void OnApplicationQuit()
DestroyImmediate(lineMaterial);
【上一篇】
【下一篇】
您可能还会对这些文章感兴趣!Unity中使用GL在Camera上画线 - xiewqe123的博客 - CSDN博客
Unity中使用GL在Camera上画线
Unity中使用GL在Camera上画线
using System.C
using System.Collections.G
using UnityE
public class joint
public Vector3
public Vector3
public class GLTest : MonoBehaviour {
public Color lineColor = Color.
public Shader fadeShader = null;
[Range(0.0f,0.5f)]
public float
private Material fadeMaterial = null;
void Awake()
fadeMaterial = (fadeShader != null) ? new Material(fadeShader) : new Material(Shader.Find("Unlit/Color"));
void Start () {
void Update () {
void OnPostRender()
fadeMaterial.SetPass(0);
fadeMaterial.color = lineC
GL.PushMatrix();
GL.LoadOrtho();
GL.Begin(GL.LINES);
Vector3 directionx = (new Vector3(0.5f, 0.5f, 0) - Vector3.zero).
Vector3 directiony = (new Vector3(0.5f, 0.5f, 0) - new Vector3(1, 0, 0)).
GLDrawLine(new Vector3(0, 0, 0) + directionx * space, new Vector3(0, 1, 0) - directiony * space);
GLDrawLine(new Vector3(0, 0, 0) + directionx * space, new Vector3(1, 0, 0) + directiony * space);
GLDrawLine(new Vector3(0, 1, 0) - directiony * space, new Vector3(1, 1, 0) - directionx * space);
GLDrawLine(new Vector3(1, 0, 0) + directiony * space, new Vector3(1, 1, 0) - directionx * space);
GL.PopMatrix();
void GLDrawLine(Vector3 beg, Vector3 end)
GL.Vertex3(beg.x, beg.y, beg.z);
GL.Vertex3(end.x, end.y, end.z);
如果要给线加宽度就不能使用GL.LINES,而要使用GL.QUADS。就是每一条线都是一个矩形的片代替。
以上方法是在Camra正交矩阵下绘制,如果要在世界坐标系中绘制就不需要调GL.LoadOrtho();这时就需要将Camera视图上的点转化成世界坐标系中的点来绘制。
float nearClip = mainCamera.nearClipPlane + 0.00001f;
Vector3 p1 = mainCamera.ViewportToWorldPoint(new Vector3(space, space, nearClip));
Vector3 p2 =
mainCamera.ViewportToWorldPoint(new Vector3(space, 1 - space, nearClip));
Vector3 p3 = mainCamera.ViewportToWorldPoint(new Vector3(linewidth + space, 1 - space, nearClip));
Vector3 p4 = mainCamera.ViewportToWorldPoint(new Vector3(linewidth + space, space, nearClip));
GL.Vertex(p1);
GL.Vertex(p2);
GL.Vertex(p3);
GL.Vertex(p4);
我的热门文章相关文章推荐
图形化调试可以加速开发。
例如在战斗中,可能需要知道所有单位的仇恨值,如果这些信息全打log的话,很难有直观感受,
而如果在Scene窗口里,单位头顶有一个球,越红表示仇恨越高,越暗表示仇...
不记得在哪里看到的代码,效果很简单,修改了一下,可以用,还是有一定的参考价值
using UnityE
using System.C
public class ...
本文永久地址:/article/77.aspx,【文章转载请注明出处!】
在前两篇中,我们使用了 Graphics(查看详情)以及 Line Rend...
这个是画线部分
private Vector3[] lineP
public int m_LineC
public int m_PointU
private var cur : int = 0;
private var orgP
private var endP
static var lineMat...
开发过程中遇到了一个问题,在UI上动态画弧线,花了一天的时间,终于解决了,拿来和大家分享一下(个人场景里只有UI)。
我才用的动态画线的方法是GL画线,有一定的性能开销,unity版本5.3.2.。...
最近做项目的时候,有一个需要从摄像机发出一条射线,当射线检测到有碰撞物体的时候,点击鼠标左键开始画线。我是创立了一个平板drawing,当然Cube什么的也是可以的。
LineRenderer线渲染器主要是用于在3D中渲染线段,虽然我们也可以使用GL图像库来渲染线段,但是使用LineRenderer我们可以对线段进行更多的操作,例如:设置颜色,宽度等。在这里要注意L...
今天在群里看见有个小伙在问Game视图寻路时怎么画线。更多精彩请关注【狗刨学习网】
正好前几天写了个寻路,而且自己也不知道具体怎么在寻路时画线,所以决定帮帮他,...
在Unity3D中绘制一个平面图形可不容易,可别惯性思维觉得,嗯,这引擎3D的事情都能解决了,2D的不叫事情。其实除去布置UI,在Unity3D中绘制一个2D平面图形是很蛋疼的一件事情。不然的话,也不...
他的最新文章
讲师:董晓杰
讲师:姚远
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)();画线, 有办法修改线的粗细么.
要评论请先&或者&
没有GL不支持全部OpenGL操作命令 不能设置线宽或者pattern几种办法自己重复画线或者画Quad代替线实现宽度用Unity的LineRender用指定贴图材质画Quad 可以实现虚线神马的效果
各位知道画线后怎么选中线对象吗?
:没有GL不支持全部OpenGL操作命令 不能设置线宽或者pattern几种办法自己重复画线或者画Quad代替线实现宽度用Unity的LineRender用指定贴图材质画Quad 可以实现虚线神马的效果 能说的具体点吗?没明白虚线到底是怎么画的……
:能说的具体点吗?没明白虚线到底是怎么画的…… 那个 Quad 居然指的是啥啊?}

我要回帖

更多关于 unity 异步加载清除 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信