- Home /
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
Answer by Adam-Mechtley · Apr 12, 2017 at 10:47 AM
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.
}
Answer by yasirkula · Aug 05, 2021 at 10:10 AM
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;
}
}
}
Your answer
Follow this Question
Related Questions
in editor object placement by script in editor 1 Answer
Building Plugins only for editor 1 Answer
how to save/retreive data on server using web service , web api 0 Answers
How do i determin if an objects rotation is between 2 values on each axis? 0 Answers
How to lock rotation in z of my camera while rotating the camera by using mobile gyroscope input 0 Answers