I’m trying to assign a component via an Editor script. Is there another way to attach a component other than the menu or drag-n-drop a behaviour script?
The immediate use is to assign a component to all of the selected objects. Of course, it would be helpful if Selection would return items selected in the Project pane.
Sam
Wow. Nothing like hiding in plain sight.
Anyway, for posterity:
static function AssignScript ()
{
var selectedObjects = Selection.gameObjects;
if(selectedObjects)
{
for(var o : GameObject in selectedObjects)
{
o.AddComponent(component);
}
}
}
Oh, and Selection.objects will return a script selected in the Project pane.
Selection.GetFiltered(Object,SelectionMode.Editable) will also return scripts.
Selection.GetFiltered(Behaviour,SelectionMode.Editable) will not, for reasons I don’t understand. Component and MonoBehaviour don’t return anything either as types.
At this point then I’m not sure how to filter out a mixed selection. I’ll just go by selection order–Oh, right. You can’t mix selections between Scene and Project. I’ll go back to the EditorWindow.
Speaking of which, is there some documentation somewhere on the EditorWindow? The Script Reference pages are rather devoid of examples. The best example I found was here:
http://forum.unity3d.com/viewtopic.php?t=13426&highlight=editorwindow
Sam