Editor Scripting: Bounds editor with BoxCollider-like scene controls
I've come across a few scenarios for "Faking" Colliders using Bounds
- mainly when I only need to keep an object inside a certain area (using Bounds.Contains(Vector3)
), and don't want it to participate in physics.
(I know I could use a Trigger for this, but that would require a dedicated layer, which isn't an option as my game is out of layers)
I created a BoundsHolder script, which uses local size/center to calculate Bounds.
I display them in editor using Gizmos.DrawWireCube
(src available upon request)- this works just fine as seen below:
But I would like to add the drag controls BoxCollider
has for enlarging my bounds:
I've browsed the docs for Gizmos
and Handles
- But all of the functions there seem to be about drawing cubes, not resizing tools.
Is there a built in tool to recreate this I'm missing?
If not- what would be the best way to go about this?
Bonus question- My BoundsHolder uses UnityEngine.Bounds
which is axis-aligned and doesn't support rotation. Is there an alternative version that supports rotation? (and still provides the Contains(Vector3)
API?)
Thanks
Answer by tombuben · Mar 05, 2020 at 12:13 PM
I also wonder about this. There seems to be BoxBoundsHandle, but from what I can see that one is still only axis aligned and there is no way to rotate it when calling DrawHandle()...
Answer by wolilio · Aug 13, 2020 at 10:18 AM
display not axis aligend box handle ,see https://answers.unity.com/questions/1339686/boxboundshandle-rotation.html
Contains(Vector3) Api
convert point to the local space of the box ,see https://docs.unity3d.com/ScriptReference/Transform.InverseTransformPoint.html