public void AddComponent(Entity entity, ComponentType componentType)
        {
            CheckAccess();

            m_EntityComponentStore->AssertCanAddComponent(entity, componentType);
            EntityManagerChangeArchetypeUtility.AddComponent(entity, componentType, EntityComponentStore, ManagedComponentStore, EntityGroupManager);
        }
Exemple #2
0
        internal void AddComponent(MatchingArchetypeList archetypeList, EntityQueryFilter filter,
                                   ComponentType componentType)
        {
            var jobHandle = new JobHandle();

            using (var chunks = ComponentChunkIterator.CreateArchetypeChunkArray(archetypeList, Allocator.TempJob, out jobHandle, ref filter))
            {
                jobHandle.Complete();
                if (chunks.Length == 0)
                {
                    return;
                }

                BeforeStructuralChange();
                EntityComponentStore->AssertCanAddComponent(chunks, componentType);

                using (var entityBatchList = m_EntityComponentStore->CreateEntityBatchList(chunks))
                {
                    EntityManagerChangeArchetypeUtility.AddComponent(entityBatchList, componentType, 0,
                                                                     EntityComponentStore,
                                                                     ManagedComponentStore,
                                                                     EntityGroupManager);
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Adds a component to a set of entities.
 /// </summary>
 /// <remarks>
 /// Adding a component changes an entity's archetype and results in the entity being moved to a different
 /// chunk.
 ///
 /// The added components have the default values for the type.
 ///
 /// If an <see cref="Entity"/> object in the `entities` array refers to an entity that has been destroyed, this function
 /// throws an ArgumentError exception.
 ///
 /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
 /// currently running Jobs to complete before creating these chunks and no additional Jobs can start before
 /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not
 /// be able to make use of the processing power of all available cores.
 /// </remarks>
 /// <param name="entities">An array of Entity objects.</param>
 /// <param name="componentType">The type of component to add.</param>
 public void AddComponent(NativeArray <Entity> entities, ComponentType componentType)
 {
     BeforeStructuralChange();
     using (var entityBatchList = m_EntityComponentStore->CreateEntityBatchList(entities))
     {
         EntityManagerChangeArchetypeUtility.AddComponent(entityBatchList, componentType, 0, EntityComponentStore, ManagedComponentStore, EntityGroupManager);
     }
 }
Exemple #4
0
        // ----------------------------------------------------------------------------------------------------------
        // INTERNAL
        // ----------------------------------------------------------------------------------------------------------

        internal void AddComponent(Entity entity, ComponentType componentType, bool ignoreDuplicateAdd)
        {
            if (ignoreDuplicateAdd && HasComponent(entity, componentType))
            {
                return;
            }

            BeforeStructuralChange();
            EntityComponentStore->AssertCanAddComponent(entity, componentType);
            EntityManagerChangeArchetypeUtility.AddComponent(entity, componentType, EntityComponentStore, ManagedComponentStore, EntityGroupManager);
        }
Exemple #5
0
        public void AddComponent(Entity entity, ComponentType componentType)
        {
            CheckAccess();
            m_EntityComponentStore->AssertCanAddComponent(entity, componentType);
            var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

            EntityManagerChangeArchetypeUtility.AddComponent(entity, componentType, EntityComponentStore, ManagedComponentStore);

            var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);

            EntityGroupManager.AddAdditionalArchetypes(changedArchetypes);
        }
Exemple #6
0
        // ----------------------------------------------------------------------------------------------------------
        // INTERNAL
        // ----------------------------------------------------------------------------------------------------------

        internal void AddComponent(Entity entity, ComponentType componentType, bool ignoreDuplicateAdd)
        {
            if (ignoreDuplicateAdd && HasComponent(entity, componentType))
            {
                return;
            }

            BeforeStructuralChange();
            var archetypeChanges = EntityComponentStore->BeginArchetypeChangeTracking();

            EntityComponentStore->AssertCanAddComponent(entity, componentType);
            EntityManagerChangeArchetypeUtility.AddComponent(entity, componentType, EntityComponentStore, ManagedComponentStore);

            var changedArchetypes = EntityComponentStore->EndArchetypeChangeTracking(archetypeChanges);

            EntityGroupManager.AddAdditionalArchetypes(changedArchetypes);
        }
Exemple #7
0
        /// <summary>
        /// Adds a component to each of the chunks identified by a EntityQuery and set the component values.
        /// </summary>
        /// <remarks>
        /// This function finds all chunks whose archetype satisfies the EntityQuery and adds the specified
        /// component to them.
        ///
        /// A chunk component is common to all entities in a chunk. You can access a chunk <see cref="IComponentData"/>
        /// instance through either the chunk itself or through an entity stored in that chunk.
        ///
        /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
        /// currently running Jobs to complete before adding the component and no additional Jobs can start before
        /// the function is finished. A sync point can cause a drop in performance because the ECS framework may not
        /// be able to make use of the processing power of all available cores.
        /// </remarks>
        /// <param name="entityQuery">The EntityQuery identifying the chunks to modify.</param>
        /// <param name="componentData">The data to set.</param>
        /// <typeparam name="T">The type of component, which must implement IComponentData.</typeparam>
        public void AddChunkComponentData <T>(EntityQuery entityQuery, T componentData) where T : struct, IComponentData
        {
            using (var chunks = entityQuery.CreateArchetypeChunkArray(Allocator.TempJob))
            {
                if (chunks.Length == 0)
                {
                    return;
                }
                BeforeStructuralChange();
                EntityComponentStore->AssertCanAddChunkComponent(chunks, ComponentType.ChunkComponent <T>());

                var type      = ComponentType.ReadWrite <T>();
                var chunkType = ComponentType.FromTypeIndex(TypeManager.MakeChunkComponentTypeIndex(type.TypeIndex));

                using (var entityBatchList = m_EntityComponentStore->CreateEntityBatchList(chunks))
                {
                    EntityManagerChangeArchetypeUtility.AddComponent(entityBatchList, chunkType, 0,
                                                                     EntityComponentStore, ManagedComponentStore, EntityGroupManager);
                    m_EntityComponentStore->SetChunkComponent <T>(entityBatchList, componentData);
                }
            }
        }