Пример #1
0
        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]);
        }
Пример #2
0
        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;
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        public bool HasNotNullComponent <T>() where T : class
        {
            var chunkComponentData = Chunk.ComponentDatas[ComponentTypeManager.GetTypeIndex <T>()];

            return(((ComponentData <T>)chunkComponentData)?[IndexInChunk] != null);
        }
Пример #6
0
 public override string ToString()
 {
     return($"{TypeId} ({ComponentTypeManager.GetTypeFromIndex(TypeId).Name})");
 }
Пример #7
0
 public static ComponentType Create(Type type)
 {
     return(new ComponentType(ComponentTypeManager.GetTypeIndex(type)));
 }
Пример #8
0
 public static ComponentType Create <T>()
 {
     return(new ComponentType(ComponentTypeManager.GetTypeIndex <T>()));
 }