diff --git a/Engine.Core/Extensions/BehaviourExtensions.cs b/Engine.Core/Extensions/BehaviourExtensions.cs new file mode 100644 index 0000000..5e4b405 --- /dev/null +++ b/Engine.Core/Extensions/BehaviourExtensions.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +using Syntriax.Engine.Core.Abstract; + +namespace Syntriax.Engine.Core; + +public static class BehaviourExtensions +{ + public static bool TryFindBehaviour(this IEnumerable gameObjects, [NotNullWhen(returnValue: true)] out T? behaviour) + { + behaviour = default; + + foreach (IGameObject gameObject in gameObjects) + if (gameObject.BehaviourController.TryGetBehaviour(out behaviour)) + return true; + + return false; + } + + public static void FindBehaviours(this IEnumerable gameObjects, List behaviours) + { + behaviours.Clear(); + List cache = []; + + foreach (IGameObject gameObject in gameObjects) + { + gameObject.BehaviourController.GetBehaviours(cache); + behaviours.AddRange(cache); + } + } +}