Add find actor by type and tag to level and actor classes. Move find actor by tag code to be by other find actor methods.

This commit is contained in:
Chandler Cox
2023-07-05 14:00:07 -05:00
parent bd0bc42adc
commit d88b93d56b
6 changed files with 240 additions and 137 deletions

View File

@@ -1337,6 +1337,20 @@ Actor* Actor::FindActor(const MClass* type, const StringView& name) const
return nullptr;
}
Actor* Actor::FindActor(const MClass* type, const Tag& tag) const
{
CHECK_RETURN(type, nullptr);
if (GetClass()->IsSubClassOf(type) && HasTag(tag))
return const_cast<Actor*>(this);
for (auto child : Children)
{
const auto actor = child->FindActor(type, tag);
if (actor)
return actor;
}
return nullptr;
}
Script* Actor::FindScript(const MClass* type) const
{
CHECK_RETURN(type, nullptr);