add search actor by parent tag
This commit is contained in:
@@ -783,6 +783,20 @@ void FindActorsRecursive(Actor* node, const Tag& tag, Array<Actor*>& result)
|
|||||||
FindActorsRecursive(child, tag, 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)
|
Actor* Level::FindActor(const Tag& tag, Actor* root)
|
||||||
{
|
{
|
||||||
PROFILE_CPU();
|
PROFILE_CPU();
|
||||||
@@ -822,6 +836,36 @@ Array<Actor*> Level::FindActors(const Tag& tag, Actor* root)
|
|||||||
return result;
|
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)
|
void Level::callActorEvent(ActorEventType eventType, Actor* a, Actor* b)
|
||||||
{
|
{
|
||||||
PROFILE_CPU();
|
PROFILE_CPU();
|
||||||
@@ -1301,7 +1345,7 @@ bool Level::SaveSceneToBytes(Scene* scene, rapidjson_flax::StringBuffer& outData
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Info
|
// 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
|
// Fire event
|
||||||
CallSceneEvent(SceneEventType::OnSceneSaved, scene, scene->GetID());
|
CallSceneEvent(SceneEventType::OnSceneSaved, scene, scene->GetID());
|
||||||
|
|||||||
@@ -397,6 +397,7 @@ public:
|
|||||||
/// <returns>Found actors list.</returns>
|
/// <returns>Found actors list.</returns>
|
||||||
API_FUNCTION() static Array<Actor*> GetActors(API_PARAM(Attributes="TypeReference(typeof(Actor))") const MClass* type);
|
API_FUNCTION() static Array<Actor*> GetActors(API_PARAM(Attributes="TypeReference(typeof(Actor))") const MClass* type);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds all the scripts of the given type in all the loaded scenes.
|
/// Finds all the scripts of the given type in all the loaded scenes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -479,6 +480,8 @@ public:
|
|||||||
/// <returns>Found actors or empty if none.</returns>
|
/// <returns>Found actors or empty if none.</returns>
|
||||||
API_FUNCTION() static Array<Actor*> FindActors(const Tag& tag, Actor* root = nullptr);
|
API_FUNCTION() static Array<Actor*> FindActors(const Tag& tag, Actor* root = nullptr);
|
||||||
|
|
||||||
|
API_FUNCTION() static Array<Actor*> FindActorsByParentTag(const Tag& tag, Actor* root = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Actor API
|
// Actor API
|
||||||
enum class ActorEventType
|
enum class ActorEventType
|
||||||
|
|||||||
Reference in New Issue
Block a user