Add "root" parameter to Level.GetScripts()

This commit is contained in:
MrCapy0
2025-01-04 09:43:33 -04:00
parent 0f847335c3
commit 5aa5c97e4c
3 changed files with 16 additions and 9 deletions

View File

@@ -1613,13 +1613,18 @@ Array<Actor*> Level::GetActors(const MClass* type, bool activeOnly)
return result;
}
Array<Script*> Level::GetScripts(const MClass* type)
Array<Script*> Level::GetScripts(const MClass* type, Actor* root)
{
Array<Script*> result;
CHECK_RETURN(type, result);
ScopeLock lock(ScenesLock);
for (int32 i = 0; i < Scenes.Count(); i++)
if (root)
::GetScripts(type, root, result);
else for (int32 i = 0; i < Scenes.Count(); i++)
::GetScripts(type, Scenes[i], result);
return result;
}

View File

@@ -66,7 +66,7 @@ namespace FlaxEngine
{
return FindActor(typeof(T)) as T;
}
/// <summary>
/// Tries to find actor of the given type and name in all loaded scenes.
/// </summary>
@@ -77,7 +77,7 @@ namespace FlaxEngine
{
return FindActor(typeof(T), name) as T;
}
/// <summary>
/// Tries to find actor of the given type and tag in a root actor or all loaded scenes.
/// </summary>
@@ -102,13 +102,14 @@ namespace FlaxEngine
}
/// <summary>
/// Finds all the scripts of the given type in all the loaded scenes.
/// Finds all the scripts of the given type in an actor or all the loaded scenes.
/// </summary>
/// <typeparam name="T">Type of the object.</typeparam>
/// <param name="root">The root to find scripts. If null, will search in all scenes</param>
/// <returns>Found scripts list.</returns>
public static T[] GetScripts<T>() where T : Script
public static T[] GetScripts<T>(Actor root = null) where T : Script
{
var scripts = GetScripts(typeof(T));
var scripts = GetScripts(typeof(T), root);
if (typeof(T) == typeof(Script))
return (T[])scripts;
if (scripts.Length == 0)

View File

@@ -469,11 +469,12 @@ public:
API_FUNCTION() static Array<Actor*> GetActors(API_PARAM(Attributes="TypeReference(typeof(Actor))") const MClass* type, bool activeOnly = false);
/// <summary>
/// Finds all the scripts of the given type in all the loaded scenes.
/// Finds all the scripts of the given type in an actor or all the loaded scenes.
/// </summary>
/// <param name="type">Type of the script to search for. Includes any scripts derived from the type.</param>
/// <param name="root">The root to find scripts. If null, will search in all scenes</param>
/// <returns>Found scripts list.</returns>
API_FUNCTION() static Array<Script*> GetScripts(API_PARAM(Attributes="TypeReference(typeof(Script))") const MClass* type);
API_FUNCTION() static Array<Script*> GetScripts(API_PARAM(Attributes="TypeReference(typeof(Script))") const MClass* type, Actor* root = nullptr);
/// <summary>
/// Tries to find scene with given ID.