Add FindActor by type and name.

This commit is contained in:
Chandler Cox
2023-06-02 15:12:55 -05:00
parent 2c809389ad
commit efed1f5b1d
3 changed files with 44 additions and 0 deletions

View File

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