public static EntityType FromComponentTypes(params ComponentType[] types) { ComponentTypeManager.Normalize(types); var typeId = HashUtility.Fletcher32(types, types.Length); if (!typesById.TryGetValue(typeId, out var type)) { type = new EntityType(types, typeId, typesById.Count); typesById.Add(typeId, type); } return(type); }
internal Group GetGroup(ComponentType[] included, ComponentType[] excluded) { ComponentTypeManager.Normalize(included); if (excluded.Length > 0) { ComponentTypeManager.Normalize(excluded); } foreach (var group in groups) { if (group.IncludeTypes.Length != included.Length) { goto nextGroup; } if (group.ExcludeTypes.Length != excluded.Length) { goto nextGroup; } for (var i = 0; i < included.Length; i++) { if (group.IncludeTypes[i].TypeIndex != included[i].TypeIndex) { goto nextGroup; } } for (var i = 0; i < excluded.Length; i++) { if (group.ExcludeTypes[i].TypeIndex != excluded[i].TypeIndex) { goto nextGroup; } } return(group); nextGroup: ; } var newGroup = new Group { IncludeTypes = included, ExcludeTypes = excluded }; groups.Add(newGroup); newGroup.Arrays = new IComponentArray[included.Length]; for (var i = 0; i < included.Length; i++) { newGroup.Arrays[i] = (IComponentArray)Activator.CreateInstance( typeof(ComponentArray <>).MakeGenericType(included[i])); } newGroup.Update(chunks); return(newGroup); }