示例#1
0
            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);
            }
示例#2
0
        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;
        }
示例#3
0
 public void AddComponent(ComponentBase component)
 {
     m_components.Add(component.GetType(), component);
     ComponentKey = m_entityLookup.CreateComponentKey(m_components.Values);
 }
示例#4
0
 public IReadOnlyList <Entity> GetEntitiesMatchingKey(ComponentKey componentKey)
 {
     return(m_entities.Values.Where(x => (x.ComponentKey & componentKey) == componentKey).ToList());
 }