Ejemplo n.º 1
0
 public void MoveEntitiesFrom(EntityManager srcEntities)
 {
     using (NativeArray <EntityRemapUtility.EntityRemapInfo> array = srcEntities.CreateEntityRemapArray(Allocator.TempJob))
     {
         this.MoveEntitiesFrom(srcEntities, array);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Moves all entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager and fills
 /// an array with their Entity objects.
 /// </summary>
 /// <remarks>
 /// After the move, the entities are managed by this EntityManager. Use the `output` array to make post-move
 /// changes to the transferred entities.
 ///
 /// Each world has one EntityManager, which manages all the entities in that world. This function
 /// allows you to transfer entities from one World to another.
 ///
 /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
 /// currently running Jobs to complete before moving the entities 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="output">An array to receive the Entity objects of the transferred entities.</param>
 /// <param name="srcEntities">The EntityManager whose entities are appropriated.</param>
 public void MoveEntitiesFrom(out NativeArray <Entity> output, EntityManager srcEntities)
 {
     using (var entityRemapping = srcEntities.CreateEntityRemapArray(Allocator.TempJob))
     {
         MoveEntitiesFromInternalAll(srcEntities, entityRemapping);
         EntityRemapUtility.GetTargets(out output, entityRemapping);
     }
 }
        /// <summary>
        /// Moves all entities managed by the specified EntityManager to the world of this EntityManager.
        /// </summary>
        /// <remarks>
        /// The entities moved are owned by this EntityManager.
        ///
        /// Each <see cref="World"/> has one EntityManager, which manages all the entities in that world. This function
        /// allows you to transfer entities from one World to another.
        ///
        /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
        /// currently running Jobs to complete before moving the entities 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="srcEntities">The EntityManager whose entities are appropriated.</param>
        public void MoveEntitiesFrom(EntityManager srcEntities)
        {
            var entityRemapping = srcEntities.CreateEntityRemapArray(Allocator.TempJob);

            try
            {
                MoveEntitiesFrom(srcEntities, entityRemapping);
            }
            finally
            {
                entityRemapping.Dispose();
            }
        }
        /// <summary>
        /// Instantiates / Copies all entities from srcEntityManager and copies them into this EntityManager.
        /// Entity references on components that are being cloned to entities inside the srcEntities set are remapped to the instantiated entities.
        /// </summary>
        public void CopyEntitiesFrom(EntityManager srcEntityManager, NativeArray <Entity> srcEntities, NativeArray <Entity> outputEntities = default)
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (outputEntities.IsCreated && outputEntities.Length != srcEntities.Length)
            {
                throw  new ArgumentException("outputEntities.Length must match srcEntities.Length");
            }
#endif

            using (var srcManagerInstances = new NativeArray <Entity>(srcEntities.Length, Allocator.Temp))
            {
                srcEntityManager.CopyEntities(srcEntities, srcManagerInstances);
                srcEntityManager.AddComponent(srcManagerInstances, ComponentType.ReadWrite <IsolateCopiedEntities>());

                var instantiated = srcEntityManager.CreateEntityQuery(new EntityQueryDesc
                {
                    All     = new ComponentType[] { typeof(IsolateCopiedEntities) },
                    Options = EntityQueryOptions.IncludeDisabled | EntityQueryOptions.IncludePrefab
                });

                using (var entityRemapping = srcEntityManager.CreateEntityRemapArray(Allocator.TempJob))
                {
                    MoveEntitiesFromInternalQuery(srcEntityManager, instantiated, entityRemapping);

                    EntityRemapUtility.GetTargets(out var output, entityRemapping);
                    RemoveComponent(output, ComponentType.ReadWrite <IsolateCopiedEntities>());
                    output.Dispose();

                    if (outputEntities.IsCreated)
                    {
                        for (int i = 0; i != outputEntities.Length; i++)
                        {
                            outputEntities[i] = entityRemapping[srcManagerInstances[i].Index].Target;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        // ----------------------------------------------------------------------------------------------------------
        // PUBLIC
        // ----------------------------------------------------------------------------------------------------------


        /// <summary>
        /// Moves all entities managed by the specified EntityManager to the world of this EntityManager.
        /// </summary>
        /// <remarks>
        /// The entities moved are owned by this EntityManager.
        ///
        /// Each <see cref="World"/> has one EntityManager, which manages all the entities in that world. This function
        /// allows you to transfer entities from one World to another.
        ///
        /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
        /// currently running Jobs to complete before moving the entities 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="srcEntities">The EntityManager whose entities are appropriated.</param>
        public void MoveEntitiesFrom(EntityManager srcEntities)
        {
            using (var entityRemapping = srcEntities.CreateEntityRemapArray(Allocator.TempJob))
                MoveEntitiesFromInternalAll(srcEntities, entityRemapping);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Moves a selection of the entities managed by the specified EntityManager to the <see cref="World"/> of this EntityManager
 /// and fills an array with their <see cref="Entity"/> objects.
 /// </summary>
 /// <remarks>
 /// After the move, the entities are managed by this EntityManager. Use the `output` array to make post-move
 /// changes to the transferred entities.
 ///
 /// Each world has one EntityManager, which manages all the entities in that world. This function
 /// allows you to transfer entities from one World to another.
 ///
 /// **Important:** This function creates a sync point, which means that the EntityManager waits for all
 /// currently running Jobs to complete before moving the entities 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="srcEntities">The EntityManager whose entities are appropriated.</param>
 /// <param name="filter">A EntityQuery that defines the entities to move. Must be part of the source
 /// World.</param>
 /// <exception cref="ArgumentException"></exception>
 public void MoveEntitiesFrom(EntityManager srcEntities, EntityQuery filter)
 {
     using (var entityRemapping = srcEntities.CreateEntityRemapArray(Allocator.TempJob))
         MoveEntitiesFromInternalQuery(srcEntities, filter, entityRemapping);
 }