zoukankan      html  css  js  c++  java
  • unity gl 画线

    using UnityEngine;
    using System.Collections;
    
    public class TGLLine : MonoBehaviour {
    
    	private static Material mat;
    
    	void Start () {
    		CreateLineMaterial();
    	}
    	
    
    	void Update () {
    	
    	}
    
    	//画线框用的mat
    	public static Material CreateLineMaterial(){
    		
    		mat = new Material("Shader "Lines/Colored Blended" {" +
    		                       "SubShader { Pass { " +
    		                       " Blend SrcAlpha OneMinusSrcAlpha " +
    		                       " ZWrite Off Cull Off Fog { Mode Off } " +
    		                       " BindChannels {" +
    		                       " Bind "vertex", vertex Bind "color", color }" +
    		                       "} } }");
    		mat.hideFlags = HideFlags.HideAndDontSave;
    		mat.shader.hideFlags = HideFlags.HideAndDontSave;
    		
    		//mat.SetPass(0);
    		
    		return mat;
    	}
    
    
    	void OnRenderObject() {
    		ShowLine(Color.green);
    	}
    
    	void ShowLine(Color c,float offsety = 0.2f)
    	{
    		//设置当前的材质
    		mat.SetPass( 0 );
    		GL.Begin( GL.LINES );
    		GL.Color(c);
    		for(int i=0;i<3;i++){
    			Vector3 p0;
    			p0.x=0f;
    			p0.z=0f;
    			p0.y=0+offsety;
    			GL.Vertex(p0);
    			
    			Vector3 p;
    			p.x=9f;
    			p.z=0f+i*2;
    			p.y=offsety;
    			GL.Vertex(p);
    		}
    
    
    		GL.End();
    	}
    }
    

  • 相关阅读:
    Linux操作系统(二)
    匿名函数和内置函数
    BeautifulSoup
    Robots协议
    列表和生成器表达式
    迭代器
    排序总结
    图论专题笔记
    Trie树的二三事QWQ
    二分答案经典入门题:)
  • 原文地址:https://www.cnblogs.com/nafio/p/9137466.html
Copyright © 2011-2022 走看看