Ejemplo n.º 1
0
        /// <summary>
        /// Sets the shared component of an entity.
        /// </summary>
        /// <remarks>
        /// Changing a shared component value of an entity results in the entity being moved to a
        /// different chunk. The entity moves to a chunk with other entities that have the same shared component values.
        /// A new chunk is created if no chunk with the same archetype and shared component values currently exists.
        ///
        /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
        /// currently running Jobs to complete before setting 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="entity">The entity</param>
        /// <param name="componentData">A shared component object containing the values to set.</param>
        /// <typeparam name="T">The shared component type.</typeparam>
        public void SetSharedComponentData <T>(Entity entity, T componentData) where T : struct, ISharedComponentData
        {
            BeforeStructuralChange();

            var typeIndex = TypeManager.GetTypeIndex <T>();

            EntityComponentStore->AssertEntityHasComponent(entity, typeIndex);

            var newSharedComponentDataIndex = m_ManagedComponentStore.InsertSharedComponent(componentData);

            EntityManagerChangeArchetypeUtility.SetSharedComponentDataIndex(entity, typeIndex, newSharedComponentDataIndex,
                                                                            EntityComponentStore, ManagedComponentStore);
            m_ManagedComponentStore.RemoveReference(newSharedComponentDataIndex);
        }
        public void SetSharedComponentData <T>(Entity entity, T componentData) where T : struct, ISharedComponentData
        {
            CheckAccess();

            var typeIndex = TypeManager.GetTypeIndex <T>();

            m_EntityComponentStore->AssertEntityHasComponent(entity, typeIndex);

            var newSharedComponentDataIndex = ManagedComponentStore.InsertSharedComponent(componentData);

            EntityManagerChangeArchetypeUtility.SetSharedComponentDataIndex(entity, typeIndex, newSharedComponentDataIndex,
                                                                            EntityComponentStore, ManagedComponentStore, EntityGroupManager);

            ManagedComponentStore.RemoveReference(newSharedComponentDataIndex);
        }
Ejemplo n.º 3
0
        internal void SetSharedComponentDataBoxed(Entity entity, int typeIndex, int hashCode, object componentData)
        {
            BeforeStructuralChange();

            EntityComponentStore->AssertEntityHasComponent(entity, typeIndex);

            var newSharedComponentDataIndex = 0;

            if (componentData != null) // null means default
            {
                newSharedComponentDataIndex = m_ManagedComponentStore.InsertSharedComponentAssumeNonDefault(typeIndex,
                                                                                                            hashCode, componentData);
            }

            EntityManagerChangeArchetypeUtility.SetSharedComponentDataIndex(entity, typeIndex,
                                                                            newSharedComponentDataIndex,
                                                                            EntityComponentStore, ManagedComponentStore);

            m_ManagedComponentStore.RemoveReference(newSharedComponentDataIndex);
        }