public void AddComponentsWithSharedComponentsWorks()
        {
            var archetype = m_Manager.CreateArchetype(typeof(EcsTestData), typeof(EcsTestSharedComp));
            var entity    = m_Manager.CreateEntity(archetype);

            var sharedComponentValue = new EcsTestSharedComp(1337);

            m_Manager.SetSharedComponentData(entity, sharedComponentValue);

            var typesToAdd = new ComponentTypes(typeof(EcsTestData3), typeof(EcsTestSharedComp2), typeof(EcsTestData2));

            m_Manager.AddComponents(entity, typesToAdd);

            Assert.AreEqual(m_Manager.GetSharedComponentData <EcsTestSharedComp>(entity), sharedComponentValue);

            var expectedTotalTypes = new ComponentTypes(typeof(EcsTestData), typeof(EcsTestData2),
                                                        typeof(EcsTestData3), typeof(EcsTestSharedComp), typeof(EcsTestSharedComp2));

            var actualTotalTypes = m_Manager.GetComponentTypes(entity);

            Assert.AreEqual(expectedTotalTypes.Length, actualTotalTypes.Length);
            for (var i = 0; i < expectedTotalTypes.Length; ++i)
            {
                Assert.AreEqual(expectedTotalTypes.GetTypeIndex(i), actualTotalTypes[i].TypeIndex);
            }

            actualTotalTypes.Dispose();
        }
        public void RemoveSharedComponent()
        {
            var cmds = new EntityCommandBuffer(Allocator.TempJob);

            var entity          = m_Manager.CreateEntity();
            var sharedComponent = new EcsTestSharedComp(10);

            m_Manager.AddSharedComponentData(entity, sharedComponent);

            cmds.RemoveComponent <EcsTestSharedComp>(entity);

            cmds.Playback(m_Manager);

            Assert.IsFalse(m_Manager.HasComponent <EcsTestSharedComp>(entity), "The shared component was not removed.");

            cmds.Dispose();
        }
Exemple #3
0
        public void SetSharedComponent()
        {
            var cmds = new EntityCommandBuffer(Allocator.TempJob);

            var entity          = m_Manager.CreateEntity();
            var sharedComponent = new EcsTestSharedComp(10);

            m_Manager.AddSharedComponentData(entity, sharedComponent);

            cmds.SetSharedComponent(entity, new EcsTestSharedComp(33));

            cmds.Playback(m_Manager);

            Assert.AreEqual(33, m_Manager.GetSharedComponentData <EcsTestSharedComp>(entity).value);

            cmds.Dispose();
        }