BREAKING CHANGE: replaced universe objects with root universe object

This commit is contained in:
2025-10-24 13:34:09 +03:00
parent a6eb67551d
commit 5a6883a87f
9 changed files with 46 additions and 29 deletions

View File

@@ -32,5 +32,5 @@ public static class UniverseExtensions
/// <typeparam name="T">Type to be searched through the <see cref="IUniverse"/>.</typeparam>
/// <returns>The specified type if found; otherwise, throws <see cref="NotFoundException"/>.</returns>
public static T FindRequired<T>(this IUniverse universe) where T : class
=> universe.Find<T>() ?? throw new NotFoundException($"{universe.GetType().FullName}({universe.Id}) does not contain any {nameof(IUniverseObject)} or {nameof(IBehaviour)} of type {typeof(T).FullName}");
=> universe.Root.BehaviourController.GetBehaviourInChildren<T>() ?? throw new NotFoundException($"{universe.GetType().FullName}({universe.Id}) does not contain any {nameof(IUniverseObject)} or {nameof(IBehaviour)} of type {typeof(T).FullName}");
}

View File

@@ -16,6 +16,21 @@ public static class UniverseObjectExtensions
return universeObject;
}
public static IEnumerator<IUniverseObject> TraverseChildren(this IUniverseObject universeObject)
{
static IEnumerable<IUniverseObject> Traverse(IUniverseObject obj)
{
foreach (IUniverseObject child in obj.Children)
{
yield return child;
foreach (IUniverseObject descendant in Traverse(child))
yield return descendant;
}
}
return Traverse(universeObject).GetEnumerator();
}
#region Universe Object Search
/// <summary>
/// Gets a <see cref="IUniverseObject"/> of the specified type.