Add Level.GetActors and Level.GetScripts

This commit is contained in:
Wojtek Figat
2021-02-09 23:31:23 +01:00
parent b8420feed1
commit 73efa35008
3 changed files with 80 additions and 10 deletions

View File

@@ -77,5 +77,33 @@ namespace FlaxEngine
{
return FindActor(id) as T;
}
/// <summary>
/// Finds all the scripts of the given type in all the loaded scenes.
/// </summary>
/// <typeparam name="T">Type of the object.</typeparam>
/// <returns>Found scripts list.</returns>
public static T[] GetScripts<T>() where T : Script
{
var scripts = GetScripts(typeof(T));
var result = new T[scripts.Length];
for (int i = 0; i < scripts.Length; i++)
result[i] = scripts[i] as T;
return result;
}
/// <summary>
/// Finds all the actors of the given type in all the loaded scenes.
/// </summary>
/// <typeparam name="T">Type of the object.</typeparam>
/// <returns>Found actors list.</returns>
public static T[] GetActors<T>() where T : Actor
{
var actors = GetActors(typeof(T));
var result = new T[actors.Length];
for (int i = 0; i < actors.Length; i++)
result[i] = actors[i] as T;
return result;
}
}
}