Esempio n. 1
0
        /// <summary>
        /// Converts the given set of entities to be part of the same scene.
        /// </summary>
        /// <param name="entityManager">The entity manager to operate on.</param>
        /// <param name="entities">The set of entities to convert.</param>
        /// <param name="guid">The unique identifier of the scene.</param>
        /// <returns>A scene view of entities.</returns>
        public static Scene Create(EntityManager entityManager, NativeArray <Entity> entities, Guid guid)
        {
            var sceneGuid = new SceneGuid {
                Guid = guid
            };
            var sceneInstanceId = new SceneInstanceId {
                InstanceId = s_NextSceneInstanceId++
            };

            for (var i = 0; i < entities.Length; i++)
            {
                var entity = entities[i];

                if (!entityManager.HasComponent <SceneGuid>(entity))
                {
                    entityManager.AddSharedComponentData(entities[i], sceneGuid);
                }
                else
                {
                    entityManager.SetSharedComponentData(entities[i], sceneGuid);
                }

                if (!entityManager.HasComponent <SceneInstanceId>(entity))
                {
                    entityManager.AddSharedComponentData(entities[i], sceneInstanceId);
                }
                else
                {
                    entityManager.SetSharedComponentData(entities[i], sceneInstanceId);
                }
            }

            return(new Scene(sceneGuid, sceneInstanceId));
        }
Esempio n. 2
0
 static internal void UnloadAllSceneInstances(SceneGuid sceneGuid)
 {
     using (var query = World.Active.EntityManager.CreateEntityQuery(ComponentType.ReadOnly <SceneGuid>()))
     {
         query.SetFilter(sceneGuid);
         World.Active.EntityManager.DestroyEntity(query);
     }
 }
Esempio n. 3
0
 public Scene(Guid sceneGuid, uint sceneInstanceId)
 {
     SceneGuid = new SceneGuid {
         Guid = sceneGuid
     };
     SceneInstanceId = new SceneInstanceId {
         InstanceId = sceneInstanceId
     };
 }
Esempio n. 4
0
        public static Scene Create(Guid guid)
        {
            var sceneGuid = new SceneGuid {
                Guid = guid
            };
            var sceneInstanceId = new SceneInstanceId {
                InstanceId = s_NextSceneInstanceId++
            };

            return(new Scene(sceneGuid, sceneInstanceId));
        }
Esempio n. 5
0
        static internal Entity LoadSceneAsync(SceneGuid sceneGuid)
        {
            var em       = World.Active.EntityManager;
            var newScene = SceneManager.Create(sceneGuid.Guid);

            var eScene = em.CreateEntity();

            em.AddComponentData(eScene, new SceneData()
            {
                Scene = newScene, Status = SceneStatus.NotYetProcessed
            });
            em.AddComponentData(eScene, new RequestSceneLoaded());

            return(eScene);
        }
Esempio n. 6
0
        static internal void UnloadAllSceneInstances(World world, SceneGuid sceneGuid)
        {
            var em = world.EntityManager;

            var ecb = new EntityCommandBuffer(Allocator.Temp);

            using (var query = em.CreateEntityQuery(ComponentType.ReadOnly <SceneLoadRequest>(), ComponentType.ReadOnly <SceneGuid>()))
            {
                query.SetSharedComponentFilter(sceneGuid);
                using (var issuedRequests = query.ToEntityArray(Allocator.Temp))
                {
                    foreach (var entity in issuedRequests)
                    {
                        var request = em.GetComponentData <SceneLoadRequest>(entity);

                        // Disabled for web builds until https://github.com/emscripten-core/emscripten/issues/8234 is resolved
                        #if !UNITY_WEBGL
                        // Cancels the request if not already complete
                        request.SceneOpHandle.Dispose();
                        #endif
                        ecb.DestroyEntity(entity);
                    }
                }
            }

            using (var query = em.CreateEntityQuery(new EntityQueryDesc()
            {
                All = new[] { ComponentType.ReadOnly <SceneGuid>() },
                None = new[] { ComponentType.ReadOnly <SceneLoadRequest>() }
            }))
            {
                query.SetSharedComponentFilter(sceneGuid);
                ecb.DestroyEntity(query);
            }
            ecb.Playback(em);
            ecb.Dispose();
        }
Esempio n. 7
0
 public Scene(SceneGuid sceneGuid, SceneInstanceId sceneInstanceId)
 {
     SceneGuid       = sceneGuid;
     SceneInstanceId = sceneInstanceId;
 }