Unity实现绘制线断二-----用GL画矩形线框-创新互联
今天有点时间,才记起来上一次写的画线框,接着上一节画线,我们这节来看一下GL画线

直接上代码
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class joint{
public Vector3 org;
public Vector3 end;
}
public class example : MonoBehaviour {
Event e;
private Vector3 orgPos;
private Vector3 endPos;
private bool canDrawLines = false;
ArrayList posAL;
ArrayList temppos;
public Material lineMaterial;
public List Pos = new List ();
void Start()
{
temppos=new ArrayList();
posAL=new ArrayList();
}
void Update()
{
if(Input.GetMouseButtonUp(0))
{
canDrawLines = true;
}
if(e.type!=null &canDrawLines)
{
if(e.type == EventType.MouseDown)
{
orgPos=Input.mousePosition;
}
if(e.type==EventType.MouseUp)
{
endPos=Input.mousePosition;
Pos.Add (endPos);
for (int i = 0; i < Pos.Count-1; i++) {
Vector3 p = Pos [i];
}
GLDrawLine (orgPos, endPos);
orgPos = endPos;
}
}
}
void GLDrawLine(Vector3 beg ,Vector3 end )
{
if(!canDrawLines)
return;
GL.PushMatrix ();
GL.LoadOrtho ();
beg.x=beg.x/Screen.width;
end.x=end.x/Screen.width;
beg.y=beg.y/Screen.height;
end.y=end.y/Screen.height;
joint tmpJoint = new joint();
tmpJoint.org=beg;
tmpJoint.end=end;
posAL.Add(tmpJoint);
lineMaterial.SetPass( 0 );
GL.Begin( GL.LINES );
GL.Color( new Color(1,1,1,1f) );
for(int i= 1;i另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享文章:Unity实现绘制线断二-----用GL画矩形线框-创新互联
新闻来源:http://www.scyingshan.cn/article/jhpdg.html


咨询
建站咨询
