/// <summary> /// Retrieves an ImmutableList<Entity> of all the /// entities in the Engine matching a Family. This list is /// automatically updated since its contacts are stored by /// reference. /// </summary> /// <param name="family">Family to match against.</param> /// <returns>ImmutableList<Entity> of the entities in the Engine.</returns> public ImmutableList <Entity> GetEntitiesFor(Family family) { if (!_familyManagers.ContainsKey(family)) { FamilyManager familyMap = new FamilyManager(family, this); familyMap.Initialize(); _familyManagers.Add(family, familyMap); foreach (Type compType in family._allComponents) { if (!_components.ContainsKey(compType)) { Type componentMapType = typeof(ComponentMap <>).MakeGenericType(compType); _components.Add(compType, (IComponentMap)Activator.CreateInstance(componentMapType, this)); _components[compType].Initialize(); } _components[compType].RegisterFamilyManager(familyMap); } foreach (Type compType in family._oneComponents) { if (!_components.ContainsKey(compType)) { Type componentMapType = typeof(ComponentMap <>).MakeGenericType(compType); _components.Add(compType, (IComponentMap)Activator.CreateInstance(componentMapType, this)); _components[compType].Initialize(); } _components[compType].RegisterFamilyManager(familyMap); } foreach (Type compType in family._excludeComponents) { if (!_components.ContainsKey(compType)) { Type componentMapType = typeof(ComponentMap <>).MakeGenericType(compType); _components.Add(compType, (IComponentMap)Activator.CreateInstance(componentMapType, this)); _components[compType].Initialize(); } _components[compType].RegisterFamilyManager(familyMap); } } return(_familyManagers[family].FamilyEntities); }