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