资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Unity实现绘制线断二-----用GL画矩形线框-创新互联

今天有点时间,才记起来上一次写的画线框,接着上一节画线,我们这节来看一下GL画线

创新互联公司主要从事网站建设、成都做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务邻水,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

直接上代码

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://cdkjz.cn/article/jhpdg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220