monery8 发表于 2012-12-16 15:55

Unity3D画直线、画点插件Vectrosity简介

具体效果在教程最后,主要用到了两段代码!比较简单实用的小教程了,虽然是英文的,不过很容易看明白的!收费的软件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.// 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;
    // 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 = Camera.mainCamera.ViewportToScreenPoint(anchor1T.position);
    linePoints = 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);
}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

feishia 发表于 2017-4-30 19:23

很不错

yz55jm 发表于 2017-4-30 19:02

顶顶多好

candyu 发表于 2017-4-30 19:16

说的非常好

candyu 发表于 2017-4-30 19:30

很好哦

starwallace 发表于 2017-4-30 19:36

不错不错

nahui026 发表于 2017-5-11 15:58

好帖就是要顶

susu 发表于 2017-5-11 16:10

真心顶

兔斯基 发表于 2017-5-11 15:40

说的非常好

兔斯基 发表于 2017-5-11 16:20

很好哦
页: [1] 2 3 4 5 6 7
查看完整版本: Unity3D画直线、画点插件Vectrosity简介