Unity3D 画线插件 Vectrosity_Simple2DLine

来源:互联网 发布:苹果电脑安装淘宝助理 编辑:程序博客网 时间:2024/05/09 16:42

http://blog.csdn.net/g__dragon/article/details/21088147

Vectrosity是一个很方便的画线插件,用它我们可以画出2D,3D,贝塞尔,圆,椭圆等各种线条图案。

:链接: http://pan.baidu.com/s/1pJjTFjt 密码: uesn

首先导入Vectrosity,导入后是这样的

打开Sences,看第一个Demo

Vectrosity插件采用的脚本都是用JS编写的,在第一个Demo中有三个脚本

,全部运行的效果是这样的。

这里我改为C# 的写法来书写脚本。

第一种最简单的方法画线:

void Start(){

VectorLine.SetLine(Color.white, new Vector2(0, 0), new Vector2(Screen.width - 1, Screen.height - 1));}

VectorLine类是Vectrosity的最基础的类,而SetLine是它的静态方法。

static VectorLine Setline(Color color,float time=Mathf.Infinity,Vector2[]/Vector[3] params points )

第一个参数设置线的颜色,第二个设置它显示的时间,默认可以不设置,第三个设置它线上的点的二维数组或三维数组用于链接二维点坐标或三维点坐标。

 

第二种方法:

void Start(){
Vector2[] linePoints= {new Vector2(0, Random.Range(0, Screen.height)),   // 第一个点在屏幕最左边
         new Vector2(Screen.width-1, Random.Range(0, Screen.height))}; // 第二个在屏幕右边,高度都随机 
// 定义一个 VectorLine 对象,名字是“Line” 使用linePoints数组内的点, 并且使用默认材质, 线的宽度是2像素
VectorLine line = new VectorLine("Line", linePoints, null, 2.0f);
// 画出这条线
line.Draw();
}

这是Vectrosity插件最常用的方法,先定义一个二维或三维数组,用于保存线内包含的点,然后再定义一个VectorLine对象 就是一个线对象,参数已解释,最后调用Draw方法画线。

用Vectrosity画线,就是这么简单。。。

 

[csharp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. using UnityEngine;  
  2. using System.Collections;  
  3. using Vectrosity;  
  4.   
  5. public class TestLine : MonoBehaviour  
  6. {   
  7.     public Material lineMaterial;  
  8.     private VectorLine line;  
  9.     private Vector2 [] points;  
  10.   
  11.     // Use this for initialization  
  12.     void Start()  
  13.     {  
  14.         points = new Vector2[]{new Vector2(100,100),new Vector2(200,200)};  
  15.         line = new VectorLine("Line", points, lineMaterial, 3f, LineType.Discrete, Joins.Weld);  
  16.     }  
  17.   
  18.     // Update is called once per frame  
  19.     void Update()  
  20.     {  
  21.         points[1] = new Vector2(Input.mousePosition.x,Input.mousePosition.y);  
  22.         line.Draw();  
  23.     }  
  24. }  


0 0
原创粉丝点击