Merge branch 'Level' of https://github.com/MrCapy0/FlaxEngine into MrCapy0-Level

# Conflicts:
#	Source/Engine/Level/Level.cpp
This commit is contained in:
Wojtek Figat
2025-02-25 22:33:12 +01:00
3 changed files with 15 additions and 10 deletions

View File

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

View File

@@ -66,7 +66,7 @@ namespace FlaxEngine
{ {
return FindActor(typeof(T)) as T; return FindActor(typeof(T)) as T;
} }
/// <summary> /// <summary>
/// Tries to find actor of the given type and name in all loaded scenes. /// Tries to find actor of the given type and name in all loaded scenes.
/// </summary> /// </summary>
@@ -77,7 +77,7 @@ namespace FlaxEngine
{ {
return FindActor(typeof(T), name) as T; return FindActor(typeof(T), name) as T;
} }
/// <summary> /// <summary>
/// Tries to find actor of the given type and tag in a root actor or all loaded scenes. /// Tries to find actor of the given type and tag in a root actor or all loaded scenes.
/// </summary> /// </summary>
@@ -102,13 +102,14 @@ namespace FlaxEngine
} }
/// <summary> /// <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> /// </summary>
/// <typeparam name="T">Type of the object.</typeparam> /// <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> /// <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)) if (typeof(T) == typeof(Script))
return (T[])scripts; return (T[])scripts;
if (scripts.Length == 0) 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); API_FUNCTION() static Array<Actor*> GetActors(API_PARAM(Attributes="TypeReference(typeof(Actor))") const MClass* type, bool activeOnly = false);
/// <summary> /// <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> /// </summary>
/// <param name="type">Type of the script to search for. Includes any scripts derived from the type.</param> /// <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> /// <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> /// <summary>
/// Tries to find scene with given ID. /// Tries to find scene with given ID.