using System; using System.Collections.Generic; namespace MfGames.Gallium; /// /// Extension methods for selecting components from a list. /// public static class SelectComponentOrDefaultExtensions { /// /// Retrieves a component from an entity and return it. If the entity does not have /// the component, then null will be returned. /// /// The entities to process. /// The component type being searched. /// A sequence of T1 or nulls. public static IEnumerable SelectComponent( IEnumerable entities, Type t1) { foreach (Entity entity in entities) { if (entity.Has(t1)) { yield return entity.Get(t1); } yield return null; } } /// /// Retrieves a component from an entity and return it. If the entity does not have /// the component, then the default value will be returned. /// /// The entities to process. /// The component type being searched. /// A sequence of T1. public static IEnumerable SelectComponentOrDefault(this IEnumerable entities) { foreach (Entity entity in entities) { if (entity.TryGet(out T1 v1)) { yield return v1; } yield return default; } } }