找回密码
 立即注册
查看: 6314|回复: 65

[脚本] Unity3D画直线、画点插件Vectrosity简介

[复制链接]
发表于 2012-12-16 15:55 | 显示全部楼层 |阅读模式

具体效果在教程最后,主要用到了两段代码!比较简单实用的小教程了,虽然是英文的,不过很容易看明白的!收费的软件Vectrosity配合使用才行

Let’s see how Vectrosity can be used to create an ineractive line.

So how is this accompished ? Open a scene. Add a GuiTexture in it. Add theDraggableGUIElement script to the GUITexture. This will serve as one of the handles. Choose an appropriate texture and adjust the width, height and pixel inset in the Inspector, under GUITexture. I choose 9, 9 and 4.  Under DraggableGUIElement I choose minX=0, maxX=1, minY=0 and maxX=0.75. This allows the GUITexture to be dragged by the mouse along the screen, 100% along the x axis, 75% along the y axis. Duplicate this game object and now we have two handles.

Now simply add the following script to the main camera.

[code=javascript]// Interactive line by Bournellis Ippokratis, for Vectrosity
// Move the white handles to manipulate the line

var lineMaterial : Material;

var anchor1T : Transform;
var anchor2T : Transform;
var myLine : VectorLine;

private var linePoints : Vector2[];

function Start () {
    // Set up the vector object camera (using the camera
    // tagged "Main Camera" by default)
    Vector.SetCamera();
    // Create an array to hold the points of the line
    linePoints = new Vector2[2];
    // Populate the array with data from
    SetLinePoints();
    // Create the line
    myLine = new VectorLine("myLine", linePoints,
     lineMaterial, 2.0, 0, 0, LineType.Continuous, Joins.Open);
    myLine.vectorObject.AddComponent(MeshCollider);
}

function SetLinePoints () {
    // Set the points of the array linePoints at the positions
    // of the GUI Textures in the slots anchor1T and anchor2T
    linePoints[0] = Camera.mainCamera.ViewportToScreenPoint(anchor1T.position);
    linePoints[1] = Camera.mainCamera.ViewportToScreenPoint(anchor2T.position);
}

function Update () {
    // By calling SetLinePoints in Update we refresh the points
    // of the line in every frame
    SetLinePoints ();
}   

function LateUpdate () {
    // Draw the line
    Vector.DrawLine(myLine);
}[/code]

You should now drag the 2 GUITextures in the slots named anchor1T and anchor2T. Hit play and it works
Feel free to post questions and suggestions. If you wish to support me, buy me a coffee

发表于 2017-4-30 19:23 | 显示全部楼层
很不错
发表于 2017-4-30 19:02 | 显示全部楼层
顶顶多好
发表于 2017-4-30 19:16 | 显示全部楼层
说的非常好
发表于 2017-4-30 19:30 | 显示全部楼层
很好哦
发表于 2017-4-30 19:36 | 显示全部楼层
不错不错
发表于 2017-5-11 15:58 | 显示全部楼层
好帖就是要顶
发表于 2017-5-11 16:10 | 显示全部楼层
真心顶
发表于 2017-5-11 15:40 | 显示全部楼层
说的非常好
发表于 2017-5-11 16:20 | 显示全部楼层
很好哦
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-12-4 16:50 , Processed in 0.169409 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表