[Making the world on the shoulders of giants]——10——Vectrosity of Unity3D utility plug-in, easy and convenient to realize 2D/3D line drawing function
table of Contents
(3) The attributes of the line
1. Blog introduction
As the tenth article of the plug-in learning category, this article introduces a line drawing tool known as Untiy's best use, Vectrosity. The blogger tried it and looked at the examples. It works well. This article is a short introduction.
2. Content
(1) Editor pre-made lines
First, after importing the plug-in, we can directly create a line segment through the Hierarchy panel, right-click>UI>VectorLine, and then you can see the generated line in the window and panel.
(2) Editor to modify the line
After we select the line, we can see that there will be draggable spheres at both ends of the line in the Scene window. We can use the sphere to change the position and length of the line
Press the Shift key and click on the Scene window, we can increase the number of line segment points
Press the Ctrl key and click on the Scene window, we can delete the points of the existing line segment, but at least two points must be saved
We can drag the position of the line as a whole by pressing the Alt key
(3) The attributes of the line
Style | Modify the overall color, width and collision box of the line |
Texture | Assign a texture to the line |
Partial Line | The lines of those segments are displayed |
Line Points | Display the coordinates of the points on the line |
Colors | Set the color and transition of each line |
Widths | Set the width and transition of each line |
(4) Code line drawing
The above are all things done in the case of the editor. Here, I will talk about drawing lines in the code. I will show you through a few small examples, and explore more functions by yourself.
//画直线
var linePoints = new List<Vector2>();
linePoints.Add (new Vector2(0, 0));
linePoints.Add (new Vector2(200,500));
var line = new VectorLine("Line", linePoints, 2.0f);
line.Draw();
所有的画线均是通过实例一个VectorLine来实现的,最基本的画线就是添加坐标后,
实例时赋值给VectorLine,最后调用Draw方法来绘制在屏幕上。
//画曲线
var line3 = new VectorLine("CurveLine", new List<Vector2>(110),null, 5.0f, LineType.Continuous, Joins.Weld);
line3.MakeCurve(new Vector2(0, 0),new Vector2(0,100),new Vector2(300,0),new Vector2(300,300),100);
line3.Draw();
我们先看VectorLine的参数信息
参数一:"CurverLine"是生成的线条在Hierarchy面板上的名字
参数二:new List<Vector2>(110) 是存放曲线点的链表,曲线的点数不能大过链表的长度
参数三:null 这里是设置线条的贴图
参数四:5.0f 这里设置线条的宽度
参数五:LineType 这里设置线条的类型
参数六:Joins 这里是设置两条线段之间的过度方式
我们再看曲线方法MakeCurve的参数
参数一:曲线的起点
参数二:曲线的参考锚点
参数三:曲线的终点
参数四:曲线的参考锚点
参数五:曲线的点数
//画圆
var line3 = new VectorLine("CurveLine", new List<Vector2>(110),null, 5.0f, LineType.Continuous, Joins.Weld);
line3.MakeCircle(new Vector3(100,100),100);
line3.Draw();
同样是先实例VectorLine,在调用画圆方法MakeCircle
我们看MakeCircle的参数
参数一:圆的圆心位置
参数二:半径
There are many ways to encapsulate, such as drawing lines around a fixed point of the model, etc., please check the documentation for details.
(5) Line collision
Lines can be added with colliders, and in certain situations can affect 3D objects, you need to set the following points
1. Check Collider for line properties
2. Render the camera VectorLine.SetCamera3D(gameObject);
3. The rigid body and collision box of the 3D model must be set to 2D
3. Push
Github:https://github.com/KingSun5
4. Conclusion
The plug-in function is still very powerful. If you need it, you can check the documentation and view the examples attached to the plug-in. If you feel that the blogger’s article is well written, you may wish to pay attention to the blogger and like the blog post. In addition, the blogger’s ability is limited. Any errors in the article are welcome to comment.
QQ exchange group: 806091680 (Chinar)
This group was created by CSDN blogger Chinar, recommend it! I am also in the group!
This article is an original article, please reprint the source of the famous author and stick to the top! ! ! !