From 36df9757b102c6a27cc3909340bac1e929c169f0 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 8 Aug 2021 20:58:19 +0200 Subject: [PATCH] Add creating Scene Graph nodes for actors inheriting from some shared custom types --- Source/Editor/SceneGraph/SceneGraphFactory.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Source/Editor/SceneGraph/SceneGraphFactory.cs b/Source/Editor/SceneGraph/SceneGraphFactory.cs index 2330d5472..62c8f7986 100644 --- a/Source/Editor/SceneGraph/SceneGraphFactory.cs +++ b/Source/Editor/SceneGraph/SceneGraphFactory.cs @@ -134,7 +134,8 @@ namespace FlaxEditor.SceneGraph try { // Try to pick custom node type for that actor object - if (CustomNodesTypes.TryGetValue(actor.GetType(), out customType)) + var type = actor.GetType(); + if (CustomNodesTypes.TryGetValue(type, out customType)) { // Use custom type _sharedArgsContainer[0] = actor; @@ -142,8 +143,21 @@ namespace FlaxEditor.SceneGraph } else { + // Check if the actor type inherits from one of the custom types but doesn't provide own node type + foreach (var e in CustomNodesTypes) + { + if (e.Key.IsAssignableFrom(type)) + { + // Use custom type + _sharedArgsContainer[0] = actor; + result = (ActorNode)Activator.CreateInstance(e.Value, _sharedArgsContainer); + break; + } + } + // Use default type for actors - result = new ActorNode(actor); + if (result == null) + result = new ActorNode(actor); } // Build children