Example #1
0
        public void AddComponent <TComponent>(Entity entity, TComponent component) where TComponent : struct, IComponent
        {
            Type componentType = typeof(TComponent);

            HashSet <Type> entityComponents = entityComponentTypes[entity];

            if (entityComponents.Contains(componentType))
            {
                return;
            }
            entityComponents.Add(componentType);

            IComponentsList componentsList;

            if (!componentLists.TryGetValue(componentType, out componentsList))
            {
                componentsList = new ComponentsList <TComponent>();
                componentLists.Add(componentType, componentsList);
            }
            componentsList.SetComponent(entity, component);

            foreach (var group in componentGroups)
            {
                if (IsComponentTypesMatchGroup(entityComponents, group.Key))
                {
                    group.Value.AddEntity(entity);
                }
            }
        }
Example #2
0
        public ComponentsList <TComponent> GetComponentsList <TComponent>() where TComponent : struct, IComponent
        {
            Type componentType = typeof(TComponent);

            IComponentsList components;

            if (componentLists.TryGetValue(componentType, out components))
            {
                return((ComponentsList <TComponent>)components);
            }

            var componentsList = new ComponentsList <TComponent>();

            componentLists.Add(componentType, componentsList);
            return(componentsList);
        }
Example #3
0
 public ComponentGroup(EntityManager entityManager)
 {
     components = entityManager.GetComponentsList <T>();
 }