Implement auto-sizing for box colliders when they are added to the scene.
This commit is contained in:
@@ -534,6 +534,8 @@ namespace FlaxEditor.Modules
|
||||
{
|
||||
node.ParentNode = parentNode;
|
||||
}
|
||||
|
||||
actor.OnActorSpawned();
|
||||
}
|
||||
|
||||
private void OnActorDeleted(Actor actor)
|
||||
|
||||
@@ -116,6 +116,15 @@ namespace FlaxEngine
|
||||
LocalTransform = Transform.Identity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called in-editor when an actor is added to the scene.
|
||||
/// If not in the editor, this function will not be called.
|
||||
/// </summary>
|
||||
public virtual void OnActorSpawned()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new child actor of the given type.
|
||||
/// </summary>
|
||||
|
||||
27
Source/Engine/Level/Actors/BoxCollider.cs
Normal file
27
Source/Engine/Level/Actors/BoxCollider.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
|
||||
namespace FlaxEngine
|
||||
{
|
||||
partial class BoxCollider
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override void OnActorSpawned()
|
||||
{
|
||||
base.OnActorSpawned();
|
||||
if (Parent is StaticModel model)
|
||||
{
|
||||
Vector3 modelScale = model.Scale;
|
||||
Vector3 modelSize = model.Box.Size;
|
||||
Vector3 modelCenter = model.Box.Center - model.Position;
|
||||
Vector3 colliderSize = modelSize / modelScale;
|
||||
Vector3 colliderCenter = modelCenter / modelScale;
|
||||
|
||||
Size = colliderSize;
|
||||
Center = colliderCenter;
|
||||
|
||||
// Undo Rotation
|
||||
Orientation *= Quaternion.Invert(Orientation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user