一个好的插件,会让你事半功倍,在Unity这个如此成熟的生态圈里,几乎常用的功能,都会有对应的插件帮助速简化开发工作,以最低的时间成本达到目的。接下来要介绍的是Unity的一款功能强大的画线插件:Vectrosity,如下图,提供了2D、3D画线、曲线等各种画线的封装,简单又相当实用。
这个插件在商城卖29.95美元
我已经把它放到CSDN的网盘里了,有需要可以下载。
插件地址:最新版本的Vectrosity5.6.1+demo+中文使用文档-Actionscript文档类资源-CSDN下载
直接下载下来即可使用,所有画线方式都有demo,直接抄作业。
一、 2D画线方式:
引入Vectrosity包,接着简单两行代码即可完成画线:
// Use this method if you need more control than you get with Vector.SetLine
using UnityEngine;
using System.Collections.Generic;
using Vectrosity;
public class Line : MonoBehaviour {
void Start () {
// Make a Vector2 list; in this case we just use 2 elements...
var linePoints = new List();
linePoints.Add (new Vector2(0, Random.Range(0, Screen.height))); // ...one on the left side of the screen somewhere
linePoints.Add (new Vector2(Screen.width-1, Random.Range(0, Screen.height))); // ...and one on the right
// Make a VectorLine object using the above points, with a width of 2 pixels
var line = new VectorLine("Line", linePoints, 2.0f);
// Draw the line
line.Draw();
}
}
二、 3D画线也是同样简单
// See Simple3D 2.js for another way of doing this that uses TextAsset.bytes instead.
// If the vector object doesn't appear, make sure the scene view isn't visible while in play mode
using UnityEngine;
using Vectrosity;
using System.Collections.Generic;
public class Simple3D : MonoBehaviour {
void Start () {
// Make a Vector3 array that contains points for a cube that's 1 unit in size
var cubePoints = new List{new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(0.5f, 0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, 0.5f)};
// Make a line using the above points, with a width of 2 pixels
var line = new VectorLine(gameObject.name, cubePoints, 2.0f);
// Make this transform have the vector line object that's defined above
// This object is a rigidbody, so the vector object will do exactly what this object does
VectorManager.ObjectSetup (gameObject, line, Visibility.Dynamic, Brightness.None);
}
}
三、其他的画线方式,有需要的直接参照demo直接用即可。
最后分享下载地地址:最新版本的Vectrosity5.6.1+demo+中文使用文档-Actionscript文档类资源-CSDN下载