diff --git a/Engine.Core/Extensions/BehaviourExtensions.cs b/Engine.Core/Extensions/BehaviourExtensions.cs index 5e4b405..28c71f8 100644 --- a/Engine.Core/Extensions/BehaviourExtensions.cs +++ b/Engine.Core/Extensions/BehaviourExtensions.cs @@ -7,18 +7,22 @@ namespace Syntriax.Engine.Core; public static class BehaviourExtensions { - public static bool TryFindBehaviour(this IEnumerable gameObjects, [NotNullWhen(returnValue: true)] out T? behaviour) + public static T? FindBehaviour(this IEnumerable gameObjects) where T : class { - behaviour = default; - foreach (IGameObject gameObject in gameObjects) - if (gameObject.BehaviourController.TryGetBehaviour(out behaviour)) - return true; + if (gameObject.BehaviourController.TryGetBehaviour(out T? behaviour)) + return behaviour; - return false; + return default; } - public static void FindBehaviours(this IEnumerable gameObjects, List behaviours) + public static bool TryFindBehaviour(this IEnumerable gameObjects, [NotNullWhen(returnValue: true)] out T? behaviour) where T : class + { + behaviour = FindBehaviour(gameObjects); + return behaviour is not null; + } + + public static void FindBehaviours(this IEnumerable gameObjects, List behaviours) where T : class { behaviours.Clear(); List cache = [];