Keep local orientation on collider spawn. Add option to keep orientation when resizing collider.
This commit is contained in:
@@ -19,12 +19,16 @@ namespace FlaxEditor.SceneGraph.Actors
|
||||
[CustomEditor(typeof(BoxCollider)), DefaultEditor]
|
||||
public class BoxColliderEditor : ActorEditor
|
||||
{
|
||||
private bool _keepLocalOrientation = false;
|
||||
/// <inheritdoc />
|
||||
public override void Initialize(LayoutElementsContainer layout)
|
||||
{
|
||||
base.Initialize(layout);
|
||||
|
||||
layout.Space(20f);
|
||||
var checkbox = layout.Checkbox("Keep Local Orientation", "Keeps the local orientation when resizing.").CheckBox;
|
||||
checkbox.Checked = _keepLocalOrientation;
|
||||
checkbox.StateChanged += box => _keepLocalOrientation = box.Checked;
|
||||
layout.Button("Resize to Fit", Editor.Instance.CodeDocs.GetTooltip(new ScriptMemberInfo(typeof(BoxCollider).GetMethod("AutoResize")))).Button.Clicked += OnResizeClicked;
|
||||
}
|
||||
|
||||
@@ -33,7 +37,7 @@ namespace FlaxEditor.SceneGraph.Actors
|
||||
foreach (var value in Values)
|
||||
{
|
||||
if (value is BoxCollider collider)
|
||||
collider.AutoResize();
|
||||
collider.AutoResize(!_keepLocalOrientation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,7 +80,7 @@ namespace FlaxEditor.SceneGraph.Actors
|
||||
return;
|
||||
}
|
||||
|
||||
((BoxCollider)Actor).AutoResize();
|
||||
((BoxCollider)Actor).AutoResize(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ void BoxCollider::SetSize(const Float3& value)
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
void BoxCollider::AutoResize()
|
||||
void BoxCollider::AutoResize(bool globalOrientation = true)
|
||||
{
|
||||
Actor* parent = GetParent();
|
||||
if (Cast<Scene>(parent))
|
||||
@@ -43,7 +43,8 @@ void BoxCollider::AutoResize()
|
||||
SetLocalPosition(Vector3::Zero);
|
||||
SetSize(parentSize / parentScale);
|
||||
SetCenter(parentCenter / parentScale);
|
||||
SetOrientation(GetOrientation() * Quaternion::Invert(GetOrientation()));
|
||||
if (globalOrientation)
|
||||
SetOrientation(GetOrientation() * Quaternion::Invert(GetOrientation()));
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
/// <summary>
|
||||
/// Resizes the collider based on the bounds of it's parent to contain it whole (including any siblings).
|
||||
/// </summary>
|
||||
API_FUNCTION() void AutoResize();
|
||||
API_FUNCTION() void AutoResize(bool globalOrientation);
|
||||
|
||||
public:
|
||||
// [Collider]
|
||||
|
||||
Reference in New Issue
Block a user