Add button to resize collider manually.

This commit is contained in:
Menotdan
2023-12-09 21:00:45 -05:00
parent 01b233af10
commit 19dbd3c4e4

View File

@@ -1,5 +1,30 @@
#if FLAX_EDITOR
using FlaxEditor.CustomEditors;
using FlaxEditor.CustomEditors.Dedicated;
#endif
namespace FlaxEngine
{
#if FLAX_EDITOR
/// <summary>
/// Dedicated custom editor for BoxCollider objects.
/// </summary>
[CustomEditor(typeof(BoxCollider)), DefaultEditor]
public class BoxColliderEditor : ActorEditor
{
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
base.Initialize(layout);
layout.Space(20f);
var autoResizeButton = layout.Button("Resize to Fit", "Resize the box collider to fit it's parent's bounds.");
BoxCollider collider = Values[0] as BoxCollider;
autoResizeButton.Button.Clicked += collider.AutoResize;
}
}
#endif
partial class BoxCollider
{
private void BoxExcluding(Actor target, ref BoundingBox output, Actor excluded)
@@ -26,6 +51,8 @@ namespace FlaxEngine
return;
}
LocalPosition = Vector3.Zero;
Vector3 parentScale = Parent.Scale;
BoundingBox parentBox = Parent.Box;
BoxExcluding(Parent, ref parentBox, this);