From 945438568341cf16988910d62e5103652d8cd266 Mon Sep 17 00:00:00 2001 From: Menotdan <32620310+Menotdan@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:46:15 -0500 Subject: [PATCH] Use the BoxColliderNode class for handling actor spawn events. --- Source/Editor/Modules/SceneModule.cs | 2 -- .../SceneGraph/Actors/BoxColliderNode.cs | 33 +++++++++++++++++++ Source/Engine/Level/Actor.cs | 9 ----- Source/Engine/Level/Actors/BoxCollider.cs | 27 --------------- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/Source/Editor/Modules/SceneModule.cs b/Source/Editor/Modules/SceneModule.cs index f5471ec33..954e3bd50 100644 --- a/Source/Editor/Modules/SceneModule.cs +++ b/Source/Editor/Modules/SceneModule.cs @@ -534,8 +534,6 @@ namespace FlaxEditor.Modules { node.ParentNode = parentNode; } - - actor.OnActorSpawned(); } private void OnActorDeleted(Actor actor) diff --git a/Source/Editor/SceneGraph/Actors/BoxColliderNode.cs b/Source/Editor/SceneGraph/Actors/BoxColliderNode.cs index 1f92eceea..8c00318db 100644 --- a/Source/Editor/SceneGraph/Actors/BoxColliderNode.cs +++ b/Source/Editor/SceneGraph/Actors/BoxColliderNode.cs @@ -8,8 +8,33 @@ using Real = System.Single; using FlaxEngine; +#if FLAX_EDITOR +using FlaxEditor.CustomEditors.Dedicated; +using FlaxEditor.CustomEditors; +#endif + namespace FlaxEditor.SceneGraph.Actors { +#if FLAX_EDITOR + /// + /// Dedicated custom editor for BoxCollider objects. + /// + [CustomEditor(typeof(BoxCollider)), DefaultEditor] + public class BoxColliderEditor : ActorEditor + { + /// + 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 + /// /// Scene tree node for actor type. /// @@ -37,5 +62,13 @@ namespace FlaxEditor.SceneGraph.Actors return base.RayCastSelf(ref ray, out distance, out normal); } + + /// + public override void PostSpawn() + { + base.PostSpawn(); + BoxCollider boxCollider = Actor as BoxCollider; + boxCollider.AutoResize(); + } } } diff --git a/Source/Engine/Level/Actor.cs b/Source/Engine/Level/Actor.cs index 7c34b5d7e..dbe8a89b5 100644 --- a/Source/Engine/Level/Actor.cs +++ b/Source/Engine/Level/Actor.cs @@ -116,15 +116,6 @@ namespace FlaxEngine LocalTransform = Transform.Identity; } - /// - /// Called in-editor when an actor is added to the scene. - /// If not in the editor, this function will not be called. - /// - public virtual void OnActorSpawned() - { - - } - /// /// Creates a new child actor of the given type. /// diff --git a/Source/Engine/Level/Actors/BoxCollider.cs b/Source/Engine/Level/Actors/BoxCollider.cs index ff560aa64..cfb6e9dde 100644 --- a/Source/Engine/Level/Actors/BoxCollider.cs +++ b/Source/Engine/Level/Actors/BoxCollider.cs @@ -5,26 +5,6 @@ using FlaxEditor.CustomEditors.Dedicated; namespace FlaxEngine { -#if FLAX_EDITOR - /// - /// Dedicated custom editor for BoxCollider objects. - /// - [CustomEditor(typeof(BoxCollider)), DefaultEditor] - public class BoxColliderEditor : ActorEditor - { - /// - 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) @@ -72,12 +52,5 @@ namespace FlaxEngine // Undo Rotation Orientation *= Quaternion.Invert(Orientation); } - - /// - public override void OnActorSpawned() - { - base.OnActorSpawned(); - AutoResize(); - } } }