Exemple #1
0
        /// <summary>
        /// Gets the value of a chunk component.
        /// </summary>
        /// <remarks>
        /// 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.
        /// </remarks>
        /// <param name="chunk">The chunk.</param>
        /// <typeparam name="T">The component type.</typeparam>
        /// <returns>A struct of type T containing the component value.</returns>
        /// <exception cref="ArgumentException">Thrown if the ArchetypeChunk object is invalid.</exception>
        public T GetChunkComponentData <T>(ArchetypeChunk chunk) where T : struct, IComponentData
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (chunk.Invalid())
            {
                throw new System.ArgumentException(
                          $"GetChunkComponentData<{typeof(T)}> can not be called with an invalid archetype chunk.");
            }
#endif
            var metaChunkEntity = chunk.m_Chunk->metaChunkEntity;
            return(GetComponentData <T>(metaChunkEntity));
        }
        /// <summary>
        /// Sets the value of a chunk component.
        /// </summary>
        /// <remarks>
        /// 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.
        /// </remarks>
        /// <param name="chunk">The chunk to modify.</param>
        /// <param name="componentValue">The component data to set.</param>
        /// <typeparam name="T">The component type.</typeparam>
        /// <exception cref="ArgumentException">Thrown if the ArchetypeChunk object is invalid.</exception>
        public static void SetChunkComponentData <T>(this EntityManager manager, ArchetypeChunk chunk, T componentValue) where T : class, IComponentData
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (chunk.Invalid())
            {
                throw new System.ArgumentException(
                          $"SetChunkComponentData<{typeof(T)}> can not be called with an invalid archetype chunk.");
            }
#endif
            var metaChunkEntity = chunk.m_Chunk->metaChunkEntity;
            manager.SetComponentData <T>(metaChunkEntity, componentValue);
        }