Skip to content

Commit

Permalink
Merge pull request #47 from martindevans/find_system_in_group
Browse files Browse the repository at this point in the history
System Group Query
  • Loading branch information
genaray authored Nov 14, 2023
2 parents d6f2be5 + a915e34 commit 7c82480
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Arch.System/Systems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,28 @@ public Group<T> Add(ISystem<T> system)

return this;
}


/// <summary>
/// Get all systems which can be cast into the given type
/// </summary>
/// <typeparam name="G"></typeparam>
/// <returns></returns>
public IEnumerable<G> Get<G>()
where G : ISystem<T>
{
foreach (var item in _systems)
{
if (item.System is G sys)
yield return sys;

if (item.System is Group<T> grp)
{
foreach (var nested in grp.Get<G>())
yield return nested;
}
}
}

/// <summary>
/// Initializes all <see cref="ISystem{T}"/>'s in this <see cref="Group{T}"/>.
/// </summary>
Expand Down

0 comments on commit 7c82480

Please sign in to comment.