예제 #1
0
        public void EntityPatcher_ApplyChanges_WithChunkData_ManagedComponents()
        {
            using (var differ = new EntityManagerDiffer(SrcEntityManager, Allocator.TempJob))
            {
                var    guid   = CreateEntityGuid();
                var    entity = SrcEntityManager.CreateEntity();
                Entity dstRootEntity;
                // Chunk component is added but no values are copied
                // Because chunks are generally caches and thus must be rebuildable automatically.
                // They are also likely a totally different set of chunks.
                // Diff & Patch is generally working against entities not on chunk level
                {
                    SrcEntityManager.AddComponentData(entity, guid);
                    SrcEntityManager.AddComponentData(entity, new EcsTestData(1));
                    SrcEntityManager.AddChunkComponentData <EcsTestData2>(entity);
                    SrcEntityManager.SetChunkComponentData(SrcEntityManager.GetChunk(entity), new EcsTestData2(3));
                    SrcEntityManager.AddChunkComponentData <EcsTestManagedComponent>(entity);
                    SrcEntityManager.SetChunkComponentData(SrcEntityManager.GetChunk(entity), new EcsTestManagedComponent()
                    {
                        value = "SomeString"
                    });

                    PushChanges(differ, DstEntityManager);

                    dstRootEntity = GetEntity(DstEntityManager, guid);
                    Assert.AreEqual(1, DstEntityManager.GetComponentData <EcsTestData>(dstRootEntity).value);
                    Assert.IsTrue(DstEntityManager.HasChunkComponent <EcsTestData2>(dstRootEntity));
                    Assert.IsTrue(DstEntityManager.HasChunkComponent <EcsTestManagedComponent>(dstRootEntity));
                    Assert.AreEqual(0, DstEntityManager.GetChunkComponentData <EcsTestData2>(dstRootEntity).value0);
                    Assert.AreEqual(null, DstEntityManager.GetChunkComponentData <EcsTestManagedComponent>(dstRootEntity));
                    Assert.AreEqual(1, DstEntityManager.CreateEntityQuery(typeof(ChunkHeader)).CalculateEntityCount());
                }

                // Changing Chunk component creates no diff
                {
                    SrcEntityManager.SetChunkComponentData(SrcEntityManager.GetChunk(entity), new EcsTestData2(7));
                    SrcEntityManager.SetChunkComponentData(SrcEntityManager.GetChunk(entity), new EcsTestManagedComponent()
                    {
                        value = "SomeOtherString"
                    });
                    using (var changes = differ.GetChanges(EntityManagerDifferOptions.Default, Allocator.Temp))
                    {
                        Assert.IsFalse(changes.AnyChanges);
                    }
                }

                // Removing chunk component, removes chunk component again
                {
                    SrcEntityManager.RemoveChunkComponent <EcsTestData2>(entity);
                    SrcEntityManager.RemoveChunkComponent <EcsTestManagedComponent>(entity);
                    PushChanges(differ, DstEntityManager);
                    Assert.IsFalse(DstEntityManager.HasChunkComponent <EcsTestData2>(dstRootEntity));
                    Assert.IsFalse(DstEntityManager.HasChunkComponent <EcsTestManagedComponent>(dstRootEntity));
                    Assert.AreEqual(0, DstEntityManager.CreateEntityQuery(typeof(ChunkHeader)).CalculateEntityCount());
                }
            }
        }