I made a simple editor script for Vectrosity 1.4. Its purpose is to allow users to draw straight continuous lines ( actually polylines, i.e continuous line segments ) in the scene view. Think of it as a primitive line editor.
It consists of two parts: The first part is the IppoLine1.js script that deals with line definition and update in runtime.
// Add - Remove points in inspector
var linePoints:Vector3[];
// Proposed material : VectorLine
var myMat:Material;
var line : VectorLine;
function Start ()
{
//Define the line, I found a width of 4.0 to be satisfacatory
line = new VectorLine("Line", linePoints, myMat, 4.0, LineType.Continuous);
// Draw the line
Vector.DrawLine3DAuto(line, transform);
}
function Update()
{
//This line forces the line to Update
// and places it at (0,0,0) of local space of gameObject
Vector.DrawLine3D(line, transform);
}
The second script, CustomEditorIppoLine1.js deals with the manipulation of the line points in Scene view and drawing of a line in it.
@CustomEditor( IppoLine1 )
class CustomEditorIppoLine1 extends Editor
{
//Those Vector3 will define the points through which the line will pass in Scene view
var positions : Vector3[];
//This allows to do stuff in Scene view
function OnSceneGUI()
{
Handles.color = Color.white;
positions = new Vector3[target.linePoints.Length];
var i :int =0;
for(var item:Vector3 in target.linePoints )
{
// itemWorld is the position in world space of the FreeMoveHandle
var itemWorld:Vector3 = Handles.FreeMoveHandle( target.transform.TransformPoint(item), Quaternion.identity, 0.2, Vector3.zero, Handles.RectangleCap);
// move the linePoint[x] to the itemWorld position, translated in local space
item = target.transform.InverseTransformPoint(itemWorld);
Handles.DotCap(0, itemWorld, Quaternion.identity, 0.1);
positions[i] = itemWorld;
++i;
}
if (GUI.changed)
{
EditorUtility.SetDirty (target);
}
//Draw line in Scene view
Handles.DrawAAPolyLine( 0.1, positions);
}
}
Usage: Create a new project. Add VectrosityDemos_Unity3.unitypackage in it.
Create one folder called Editor and place CustomEditorIppoLine1.js in it. Add IppoLine1.js in your project too.
Make a new scene, add a new GameObject, place it at 0,0,0, name it (say) Line1, add IppoLine1.js to it.
Select the Line1 in the Hierarchy. In the Inspector, below the IppoLine1(script) select VectorLine as the Material.
On the left of LinePoints there is a small arrow. Click it. Set size to (say) 2. Set Element 0 x as -1 and Element 1 x as 1.
Now you will notice that in the scene view 2 little squared appear on both sides of the game Object. Drag them around.
Those define the begining and the end of the line. If you align the scene view with the camera view, what you see in the scene
will be identical with what you will see in runtime.
To add points, set size (as mentioned before) to 3 e.t.c. The trick is that the new points can be dragged out by selecting in the scene the last point or by setting manually their value in the Elements section.
I hope you will find these scripts useful.