I just ported one my scripts over to Unity here. It’s called LineMup. It can align and distribute multiple objects within the scene. I figured it might come in handy for placing collectibles and such.
Just place the script in the “Editor” folder in the Project pane. If there isn’t an Editor folder, create it and place the script inside.
It will create a dropdown menu from which you can align and distribute your selected objects. Alignment will snap the selected objects to the “active selected object”. Distribute will evenly distribute all selected objects between the “active selected object” and the object furthest away from the active selected object. The “active selected object” is the object you’ll see in the inspector when you have multiple objects selected. It will be the first selected object if you select the objects in the Hierarchy pane, and will be the last selected object if you make your selection in the 3d view.
Hopefully that made sense. If not, I uploaded a quick demonstration video to YouTube.
Thanks anomalous_underdog. Glad to hear some folks are finding it useful. I would like to see UT implement something like this in Unity as well. I’m sure they could do it even better. Every CG program should have basic alignment and distribution snapping IMO. Not sure why so many don’t implement it. It’s simple enough. Maybe we’ll see it in a future version.
I just noticed that I had misspelled my own name, 'doh. I corrected it on the Wiki. I also noticed that the file name had a number after it for some reason. Must have occurred during the forum update. Anyway, updated the corrected version in the first post as well.
I needed the objects to be ordered, so tweaked the script to consider the distance as well. Basically doing a first rough pass at ordering objects, then invoking linemup (this was for a xylophone where order of note bars matters).
Here is the change to the script, it seems in place sorting of transform doesn’t work so this is a bit clunky:
replace
// update every object in the selection to distribute evenly
for (var transform in Selection.transforms)
with:
// update every object in the selection to distribute evenly
var sortedTransforms = new Transform[Selection.transforms.length];
var sortIndex=0;
for (var transform in Selection.transforms)
{
sortedTransforms[sortIndex++]=transform;
}
System.Array.Sort(sortedTransforms, function(a,b){return Vector3.Distance(a.position, firstObj.position)-Vector3.Distance(b.position, firstObj.position);});
for (var transform in sortedTransforms){