Ejemplo n.º 1
0
        public IEnumerator LoadSubscene_With_PostLoadCommandBuffer([Values] bool loadAsync, [Values] bool addCommandBufferToSection)
        {
            var postLoadCommandBuffer = new PostLoadCommandBuffer();

            postLoadCommandBuffer.CommandBuffer = new EntityCommandBuffer(Allocator.Persistent, PlaybackPolicy.MultiPlayback);
            var postLoadEntity = postLoadCommandBuffer.CommandBuffer.CreateEntity();

            postLoadCommandBuffer.CommandBuffer.AddComponent(postLoadEntity, new TestProcessAfterLoadData {
                Value = 42
            });

            using (var world = TestWorldSetup.CreateEntityWorld("World", false))
            {
                if (addCommandBufferToSection)
                {
                    var resolveParams = new SceneSystem.LoadParameters
                    {
                        Flags = SceneLoadFlags.BlockOnImport | SceneLoadFlags.DisableAutoLoad
                    };
                    world.GetOrCreateSystem <SceneSystem>().LoadSceneAsync(m_SceneGUID, resolveParams);
                    world.Update();
                    var section = world.EntityManager.CreateEntityQuery(typeof(SceneSectionData)).GetSingletonEntity();
                    world.EntityManager.AddComponentData(section, postLoadCommandBuffer);
                }

                var loadParams = new SceneSystem.LoadParameters
                {
                    Flags = loadAsync ? 0 : SceneLoadFlags.BlockOnImport | SceneLoadFlags.BlockOnStreamIn
                };

                Assert.IsTrue(m_SceneGUID.IsValid);

                var scene = world.GetOrCreateSystem <SceneSystem>().LoadSceneAsync(m_SceneGUID, loadParams);
                if (!addCommandBufferToSection)
                {
                    world.EntityManager.AddComponentData(scene, postLoadCommandBuffer);
                }

                if (loadAsync)
                {
                    while (!world.GetExistingSystem <SceneSystem>().IsSceneLoaded(scene))
                    {
                        world.Update();
                        yield return(null);
                    }
                }
                else
                {
                    world.Update();
                    Assert.IsTrue(world.GetExistingSystem <SceneSystem>().IsSceneLoaded(scene));
                }

                var ecsTestDataQuery = world.EntityManager.CreateEntityQuery(typeof(TestProcessAfterLoadData));
                Assert.AreEqual(1, ecsTestDataQuery.CalculateEntityCount());
                Assert.AreEqual(43, ecsTestDataQuery.GetSingleton <TestProcessAfterLoadData>().Value);
            }

            // Check that command buffer has been Disposed
            Assert.IsFalse(postLoadCommandBuffer.CommandBuffer.IsCreated);
        }
        private static PostLoadCommandBuffer CreateTestProcessAfterLoadDataCommandBuffer(int value)
        {
            var postLoadCommandBuffer = new PostLoadCommandBuffer();

            postLoadCommandBuffer.CommandBuffer = new EntityCommandBuffer(Allocator.Persistent, PlaybackPolicy.MultiPlayback);
            var postLoadEntity = postLoadCommandBuffer.CommandBuffer.CreateEntity();

            postLoadCommandBuffer.CommandBuffer.AddComponent(postLoadEntity, new TestProcessAfterLoadData {
                Value = value
            });
            return(postLoadCommandBuffer);
        }
Ejemplo n.º 3
0
        AsyncLoadSceneOperation CreateAsyncLoadSceneOperation(EntityManager dstManager, Entity entity, bool blockUntilFullyLoaded)
        {
            var sceneData   = EntityManager.GetComponentData <SceneSectionData>(entity);
            var sectionData = EntityManager.GetComponentData <ResolvedSectionPath>(entity);

            var entitiesBinaryPath = sectionData.ScenePath.ToString();
            var resourcesPath      = sectionData.HybridPath.ToString();
            NativeArray <Entities.Hash128> dependencies = default;

            if (EntityManager.HasComponent <BundleElementData>(entity))
            {
                var depBuffer = EntityManager.GetBuffer <BundleElementData>(entity);
                dependencies = new NativeArray <Entities.Hash128>(depBuffer.AsNativeArray().Reinterpret <Entities.Hash128>(), Allocator.Persistent);
            }

#if !UNITY_DISABLE_MANAGED_COMPONENTS
            PostLoadCommandBuffer postLoadCommandBuffer = null;
            if (EntityManager.HasComponent <PostLoadCommandBuffer>(entity))
            {
                postLoadCommandBuffer = EntityManager.GetComponentData <PostLoadCommandBuffer>(entity);
            }
            else if (EntityManager.HasComponent <SceneEntityReference>(entity))
            {
                var sceneEntity = EntityManager.GetComponentData <SceneEntityReference>(entity).SceneEntity;
                if (EntityManager.HasComponent <PostLoadCommandBuffer>(sceneEntity))
                {
                    postLoadCommandBuffer = EntityManager.GetComponentData <PostLoadCommandBuffer>(sceneEntity);
                }
            }

            if (postLoadCommandBuffer != null)
            {
                postLoadCommandBuffer = (PostLoadCommandBuffer)postLoadCommandBuffer.Clone();
            }
#endif
            return(new AsyncLoadSceneOperation(new AsyncLoadSceneData
            {
                ScenePath = entitiesBinaryPath,
                SceneSize = sceneData.DecompressedFileSize,
                CompressedSceneSize = sceneData.FileSize,
                Codec = sceneData.Codec,
                ExpectedObjectReferenceCount = sceneData.ObjectReferenceCount,
                ResourcesPathObjRefs = resourcesPath,
                EntityManager = dstManager,
                BlockUntilFullyLoaded = blockUntilFullyLoaded,
                Dependencies = dependencies,
#if !UNITY_DISABLE_MANAGED_COMPONENTS
                PostLoadCommandBuffer = postLoadCommandBuffer
#endif
            }));
        }
        AsyncLoadSceneOperation CreateAsyncLoadSceneOperation(EntityManager dstManager, Entity entity, bool blockUntilFullyLoaded)
        {
            var sceneData   = EntityManager.GetComponentData <SceneSectionData>(entity);
            var sectionData = EntityManager.GetComponentData <ResolvedSectionPath>(entity);

            var entitiesBinaryPath = sectionData.ScenePath.ToString();
            var resourcesPath      = sectionData.HybridPath.ToString();

#if !UNITY_DISABLE_MANAGED_COMPONENTS
            PostLoadCommandBuffer postLoadCommandBuffer = null;
            if (EntityManager.HasComponent <PostLoadCommandBuffer>(entity))
            {
                postLoadCommandBuffer = EntityManager.GetComponentData <PostLoadCommandBuffer>(entity);
            }
            else if (EntityManager.HasComponent <SceneEntityReference>(entity))
            {
                var sceneEntity = EntityManager.GetComponentData <SceneEntityReference>(entity).SceneEntity;
                if (EntityManager.HasComponent <PostLoadCommandBuffer>(sceneEntity))
                {
                    postLoadCommandBuffer = EntityManager.GetComponentData <PostLoadCommandBuffer>(sceneEntity);
                }
            }

            if (postLoadCommandBuffer != null)
            {
                postLoadCommandBuffer = (PostLoadCommandBuffer)postLoadCommandBuffer.Clone();
            }
#endif
            return(new AsyncLoadSceneOperation(new AsyncLoadSceneData
            {
                ScenePath = entitiesBinaryPath,
                SceneSize = sceneData.FileSize,
                ExpectedObjectReferenceCount = sceneData.ObjectReferenceCount,
                ResourcesPathObjRefs = resourcesPath,
                EntityManager = dstManager,
                BlockUntilFullyLoaded = blockUntilFullyLoaded,
#if !UNITY_DISABLE_MANAGED_COMPONENTS
                PostLoadCommandBuffer = postLoadCommandBuffer
#endif
            }));
        }