public void SerializingSharedComponent_WhenMoreThanOne_AndProxyHasDisallowMultiple_DoesNotCrash()
        {
            for (var i = 0; i < 20; ++i)
            {
                var entity = m_Manager.CreateEntity();
                m_Manager.AddSharedComponentData(entity, new MockSharedDisallowMultiple {
                    Value = i
                });
                m_Manager.AddComponentData(entity, new EcsTestData(i));
            }

            var        writer           = new TestBinaryWriter();
            GameObject sharedComponents = null;

            try
            {
                Assert.That(
                    () => SerializeUtilityHybrid.Serialize(m_Manager, writer, out sharedComponents),
                    Throws.ArgumentException.With.Message.Matches(@"\bDisallowMultipleComponent\b")
                    );
            }
            finally
            {
                writer.Dispose();
                if (sharedComponents != null)
                {
                    GameObject.DestroyImmediate(sharedComponents);
                }
            }
        }
示例#2
0
        public void SerializeDoesntRemapOriginalHeapBuffers()
        {
            var dummyEntity = CreateEntityWithDefaultData(0); //To ensure entity indices are offset

            var e1 = m_Manager.CreateEntity();

            m_Manager.AddComponentData(e1, new EcsTestData(1));
            var e2 = m_Manager.CreateEntity();

            m_Manager.AddComponentData(e2, new EcsTestData2(2));

            m_Manager.AddBuffer <TestBufferElement>(e1);
            var buffer1 = m_Manager.GetBuffer <TestBufferElement>(e1);

            for (int i = 0; i < 1024; ++i)
            {
                buffer1.Add(new TestBufferElement {
                    entity = e2, value = 2
                });
            }

            m_Manager.AddBuffer <TestBufferElement>(e2);
            var buffer2 = m_Manager.GetBuffer <TestBufferElement>(e2);

            for (int i = 0; i < 8; ++i)
            {
                buffer2.Add(new TestBufferElement {
                    entity = e1, value = 1
                });
            }

            m_Manager.DestroyEntity(dummyEntity);
            // disposed via reader
            var writer = new TestBinaryWriter();

            int[] sharedData;
            SerializeUtility.SerializeWorld(m_Manager, writer, out sharedData);

            buffer1 = m_Manager.GetBuffer <TestBufferElement>(e1);
            for (int i = 0; i < buffer1.Length; ++i)
            {
                Assert.AreEqual(e2, buffer1[i].entity);
                Assert.AreEqual(2, buffer1[i].value);
            }

            buffer2 = m_Manager.GetBuffer <TestBufferElement>(e2);
            for (int i = 0; i < buffer2.Length; ++i)
            {
                Assert.AreEqual(e1, buffer2[i].entity);
                Assert.AreEqual(1, buffer2[i].value);
            }

            writer.Dispose();
        }
示例#3
0
        public void SerializingSharedComponent_WhenMoreThanOne_AndWrapperHasDisallowMultiple_DoesNotCrash()
        {
            for (var i = 0; i < 20; ++i)
            {
                var entity = m_Manager.CreateEntity();
                m_Manager.AddSharedComponentData(entity, new MockSharedDisallowMultiple {
                    Value = i
                });
                m_Manager.AddComponentData(entity, new EcsTestData(i));
            }

            var        writer           = new TestBinaryWriter();
            GameObject sharedComponents = null;

            try
            {
                var ex = Assert.Throws <ArgumentException>(
                    () => SerializeUtilityHybrid.Serialize(m_Manager, writer, out sharedComponents)
                    );
                Assert.That(
                    ex.Message,
                    Is.EqualTo(
                        string.Format(
                            "{0} is marked with {1}, but current implementation of {2} serializes all shared components on a single GameObject.",
                            typeof(MockSharedDisallowMultipleComponent),
                            typeof(DisallowMultipleComponent),
                            nameof(SerializeUtilityHybrid.SerializeSharedComponents)
                            )
                        )
                    );
            }
            finally
            {
                writer.Dispose();
                if (sharedComponents != null)
                {
                    GameObject.DestroyImmediate(sharedComponents);
                }
            }
        }