public ref T GetComponent <T>() { var t = (ComponentData <T>)Chunk.ComponentDatas[ComponentTypeManager.GetTypeIndex <T>()]; if (t == null) { throw new EntitiesException($"Entity doesn't have component of type \"{typeof(T)}\""); } return(ref t[IndexInChunk]); }
public void SetComponent <T>(T data) { var t = (ComponentData <T>)Chunk.ComponentDatas[ComponentTypeManager.GetTypeIndex <T>()]; if (t == null) { throw new EntitiesException($"Entity doesn't have component of type \"{typeof(T)}\""); } t[IndexInChunk] = data; }
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); }
public bool HasNotNullComponent <T>() where T : class { var chunkComponentData = Chunk.ComponentDatas[ComponentTypeManager.GetTypeIndex <T>()]; return(((ComponentData <T>)chunkComponentData)?[IndexInChunk] != null); }
public override string ToString() { return($"{TypeId} ({ComponentTypeManager.GetTypeFromIndex(TypeId).Name})"); }
public static ComponentType Create(Type type) { return(new ComponentType(ComponentTypeManager.GetTypeIndex(type))); }
public static ComponentType Create <T>() { return(new ComponentType(ComponentTypeManager.GetTypeIndex <T>())); }