feat: BehaviourExtensions.FindBehaviour
This commit is contained in:
parent
ed6975bf24
commit
be06575f91
|
@ -7,18 +7,22 @@ namespace Syntriax.Engine.Core;
|
|||
|
||||
public static class BehaviourExtensions
|
||||
{
|
||||
public static bool TryFindBehaviour<T>(this IEnumerable<IGameObject> gameObjects, [NotNullWhen(returnValue: true)] out T? behaviour)
|
||||
public static T? FindBehaviour<T>(this IEnumerable<IGameObject> 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<T>(this IEnumerable<IGameObject> gameObjects, List<T> behaviours)
|
||||
public static bool TryFindBehaviour<T>(this IEnumerable<IGameObject> gameObjects, [NotNullWhen(returnValue: true)] out T? behaviour) where T : class
|
||||
{
|
||||
behaviour = FindBehaviour<T>(gameObjects);
|
||||
return behaviour is not null;
|
||||
}
|
||||
|
||||
public static void FindBehaviours<T>(this IEnumerable<IGameObject> gameObjects, List<T> behaviours) where T : class
|
||||
{
|
||||
behaviours.Clear();
|
||||
List<T> cache = [];
|
||||
|
|
Loading…
Reference in New Issue