diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index 4fa37c80d..b1c5ede2b 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -783,6 +783,20 @@ void FindActorsRecursive(Actor* node, const Tag& tag, Array& result) FindActorsRecursive(child, tag, result); } +void FindActorsRecursiveByParentTags(Actor* node, const Array& tags, Array& result) +{ + for (Tag tag : tags) + { + if (node->HasTag(tag)) { + result.Add(node); + break; + } + } + + for (Actor* child : node->Children) + FindActorsRecursiveByParentTags(child, tags, result); +} + Actor* Level::FindActor(const Tag& tag, Actor* root) { PROFILE_CPU(); @@ -822,6 +836,36 @@ Array Level::FindActors(const Tag& tag, Actor* root) return result; } +API_FUNCTION()Array Level::FindActorsByParentTag(const Tag& parentTag, Actor* root) +{ + PROFILE_CPU(); + Array result; + const Array subTags = Tags::GetSubTags(parentTag); + + if (subTags.Count() == 0) + { + return result; + } + + if (subTags.Count() == 1) + { + result = FindActors(subTags[0], root); + return result; + } + + if (root) + { + FindActorsRecursiveByParentTags(root, subTags, result); + } + else + { + for (Scene* scene : Scenes) + FindActorsRecursiveByParentTags(scene, subTags, result); + } + + return result; +} + void Level::callActorEvent(ActorEventType eventType, Actor* a, Actor* b) { PROFILE_CPU(); @@ -1301,7 +1345,7 @@ bool Level::SaveSceneToBytes(Scene* scene, rapidjson_flax::StringBuffer& outData } // Info - LOG(Info, "Scene saved! Time {0} ms", Math::CeilToInt(static_cast((DateTime::NowUTC()- startTime).GetTotalMilliseconds()))); + LOG(Info, "Scene saved! Time {0} ms", Math::CeilToInt(static_cast((DateTime::NowUTC() - startTime).GetTotalMilliseconds()))); // Fire event CallSceneEvent(SceneEventType::OnSceneSaved, scene, scene->GetID()); diff --git a/Source/Engine/Level/Level.h b/Source/Engine/Level/Level.h index ed2efe485..203930bac 100644 --- a/Source/Engine/Level/Level.h +++ b/Source/Engine/Level/Level.h @@ -397,6 +397,7 @@ public: /// Found actors list. API_FUNCTION() static Array GetActors(API_PARAM(Attributes="TypeReference(typeof(Actor))") const MClass* type); + /// /// Finds all the scripts of the given type in all the loaded scenes. /// @@ -479,6 +480,14 @@ public: /// Found actors or empty if none. API_FUNCTION() static Array FindActors(const Tag& tag, Actor* root = nullptr); + /// + /// Search actors using a parent parentTag. + /// + /// The tag to search actors with subtags belonging to this tag + /// The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. + /// Returns all actors that have subtags belonging to the given parent parentTag + API_FUNCTION() static Array FindActorsByParentTag(const Tag& parentTag, Actor* root = nullptr); + private: // Actor API enum class ActorEventType