diff --git a/Engine.Core/Extensions/GameManagerExtensions.cs b/Engine.Core/Extensions/GameManagerExtensions.cs index 577e80d..db991e6 100644 --- a/Engine.Core/Extensions/GameManagerExtensions.cs +++ b/Engine.Core/Extensions/GameManagerExtensions.cs @@ -9,11 +9,8 @@ public static class GameManagerExtensions => gameManager.InstantiateHierarchyObject(args); public static T GetRequiredHierarchyObject(this IGameManager gameManager) where T : class - { - foreach (IHierarchyObject hierarchyObject in gameManager) - if (hierarchyObject is T @object) - return @object; + => gameManager.GetHierarchyObject() ?? throw new HierarchyObjectNotFoundException($"{gameManager.GetType().FullName}({gameManager.Id}) does not contain any {nameof(IHierarchyObject)} object of type {typeof(T).FullName}"); - throw new HierarchyObjectNotFoundException($"{gameManager.GetType().FullName}({gameManager.Id}) does not contain any {typeof(T).FullName}"); - } + public static T FindRequiredBehaviour(this IGameManager gameManager) where T : class + => gameManager.FindBehaviour() ?? throw new BehaviourNotFoundException($"{gameManager.GetType().FullName}({gameManager.Id}) does not contain any {nameof(IHierarchyObject)} with {nameof(IBehaviour)} of type {typeof(T).FullName}"); }