BoxBoundsHandle rotation

Unity #5.6 introduced the new BoxBoundsHandle object to draw BoxCollider-like handles. Position, size and color can be set very easily, this is great, but there is no rotation property or field.

How to display BoxBoundsHandle with custom rotation?

EDIT:

I understand that the Bounds structure has no rotation, still it would be very useful to show the handle rotated

Hi @scanzy!

Per the documentation, all of the PrimitiveBoundsHandle classes respect Handles.matrix.

So just rotate this matrix before you draw. Something like this:

var rotation = Quaternion.AngleAxis(45f, Vector3.up);
rotatedMatrix = Handles.matrix *  Matrix4x4.TRS(Vector3.zero, rotation, Vector3.one);
using (new Handles.DrawingScope(rotatedMatrix))
{
    m_BoxBoundsHandle.DrawHandle();
    // etc.
}

BoxBoundsHandle wasn’t drawn in the correct spot for me in the above method, so I had to use the following method:

public void DrawRotatedBoxBoundsHandle( ref Vector3 position, Quaternion rotation, ref Vector3 size )
{
    Matrix4x4 matrix = Matrix4x4.TRS( Vector3.zero, rotation, Vector3.one );
    using( new Handles.DrawingScope( matrix ) )
    {
        m_BoxBoundsHandle.center = matrix.inverse.MultiplyPoint3x4( position );
        m_BoxBoundsHandle.size = size;

        EditorGUI.BeginChangeCheck();
        m_BoxBoundsHandle.DrawHandle();
        if( EditorGUI.EndChangeCheck() )
        {
            position = matrix.MultiplyPoint3x4( m_BoxBoundsHandle.center );
            size = m_BoxBoundsHandle.size;
        }
    }
}