add search actor by parent tag

This commit is contained in:
Ruan Lucas
2023-06-03 11:51:24 -04:00
parent 311637616b
commit 9c93828976
2 changed files with 48 additions and 1 deletions

View File

@@ -783,6 +783,20 @@ void FindActorsRecursive(Actor* node, const Tag& tag, Array<Actor*>& result)
FindActorsRecursive(child, tag, result);
}
void FindActorsRecursiveByParentTags(Actor* node, const Array<Tag>& tags, Array<Actor*>& 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<Actor*> Level::FindActors(const Tag& tag, Actor* root)
return result;
}
API_FUNCTION()Array<Actor*> Level::FindActorsByParentTag(const Tag& parentTag, Actor* root)
{
PROFILE_CPU();
Array<Actor*> result;
const Array<Tag> 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<float>((DateTime::NowUTC()- startTime).GetTotalMilliseconds())));
LOG(Info, "Scene saved! Time {0} ms", Math::CeilToInt(static_cast<float>((DateTime::NowUTC() - startTime).GetTotalMilliseconds())));
// Fire event
CallSceneEvent(SceneEventType::OnSceneSaved, scene, scene->GetID());