- Home /
Can Runtime Classes be used in the Editor?
I want to make a custom editor script that will save me a lot of time in the future. I want it to take a selected object (or every selected object) and 1) use Quaternion.Inverse and 2) set transform.y = -transform.y. (This mirrors the object(s) across the x-z plane.)
Is this possible? I know I can make this function work at initialization of the game, but that would be hard to tweak + extra overhead load time on startup.
I was provoked into doing this by the mirror function in AutoCAD. I was sort of disappointed I found no such tool in Unity.
Answer by karl_ · Sep 16, 2011 at 05:29 AM
Yes, this is definitely possible.
class mirrorObjs extends Editor { @MenuItem("Edit/Mirror Objects ")
static function doMirror(command : MenuCommand)
{
for(o in Selection.objects)
{
o.transform.rotation = Quaternion.Inverse(o.transform.rotation);
o.transform.y = -o.transform.y;
}
}
}
word of warning- having non-uniform scale on mesh colliders incurs a $$anonymous$$ASSIVE performance penalty. You should make sure you aren't applying this on any mesh collider objects.
this is very useful to know. With respect to the comment, I read this :"Colliders do their best to match the scale of an object. If you have a non-uniform scale (a scale which is different in each direction), only the $$anonymous$$esh Collider can match completely." here: http://unity3d.com/support/documentation/Components/class-$$anonymous$$eshCollider.html.
Does that mean that when I scale a collider (including primitives) to 1 != 1 != 1 then performance dies? If that's the case I can avoid it. If, on the other hand, this means I can't scale primitives period (to make a ground or wall for instance), then I might have to make a lot of specific art assets.
Your answer
