using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Syntriax.Engine.Core.Abstract; namespace Syntriax.Engine.Core; public static class BehaviourExtensions { public static T? FindBehaviour(this IEnumerable gameObjects) where T : class { foreach (IGameObject gameObject in gameObjects) if (gameObject.BehaviourController.GetBehaviour() is T behaviour) return behaviour; return default; } 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 = []; foreach (IGameObject gameObject in gameObjects) { gameObject.BehaviourController.GetBehaviours(cache); behaviours.AddRange(cache); } } }