public ComponentKey CreateComponentKey(params Type[] componentTypes) { var key = ComponentKey.Empty; foreach (var type in componentTypes) { if (!m_manager.m_componentTypeToId.TryGetValue(type, out int id)) { throw new InvalidOperationException($"Specified type has not been registered: {type.Name}"); } key |= ComponentKey.CreateFromComponentId(id); } return(key); }
public void CloneFrom(Entity that) { var thisComponentTypes = m_components.Keys.ToHashSet(); var thatComponentTypes = that.m_components.Keys.ToHashSet(); HashSet <Type> componentTypesInBoth = new HashSet <Type>(); foreach (var type in thisComponentTypes.ToList()) { if (thisComponentTypes.Contains(type)) { thisComponentTypes.Remove(type); thatComponentTypes.Remove(type); componentTypesInBoth.Add(type); } } foreach (var typeToDelete in thisComponentTypes) { m_components.Remove(typeToDelete); } foreach (var typeToAdd in thatComponentTypes) { m_components[typeToAdd] = that.m_components[typeToAdd].Clone(); } foreach (var typeToUpdate in componentTypesInBoth) { if (that.m_components[typeToUpdate].Version > m_components[typeToUpdate].Version) { m_components[typeToUpdate] = that.m_components[typeToUpdate].Clone(); } } ComponentKey = that.ComponentKey; }
public void AddComponent(ComponentBase component) { m_components.Add(component.GetType(), component); ComponentKey = m_entityLookup.CreateComponentKey(m_components.Values); }
public IReadOnlyList <Entity> GetEntitiesMatchingKey(ComponentKey componentKey) { return(m_entities.Values.Where(x => (x.ComponentKey & componentKey) == componentKey).ToList()); }