Esempio n. 1
0
        public void GetAllEntities_WithEmptyEntity()
        {
            var entity = m_Manager.CreateEntity();

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity) },
                debugEntities);
        }
Esempio n. 2
0
        public void GetAllEntities_WithTaggedEntity()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestTag));

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity, new DebugComponent {
                    Type = typeof(EcsTestTag), Data = new EcsTestTag()
                }) },
                debugEntities);
        }
Esempio n. 3
0
        public void GetAllEntities_WithBufferElementData()
        {
            var entity = m_Manager.CreateEntity();
            var buffer = m_Manager.AddBuffer <EcsIntElement>(entity);

            buffer.Add(1);
            buffer.Add(5);
            buffer.Add(9);

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(EcsIntElement), Data = new EcsIntElement[] { 1, 5, 9 }
                }) },
                debugEntities);
        }
Esempio n. 4
0
        public void GetAllEntities_WithSharedTagEntity()
        {
            var entity = m_Manager.CreateEntity(typeof(EcsTestSharedTag));

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            #if NET_DOTS
            // until ManagedComponentStore.GetSharedComponentDataBoxed supports an alternative to Activator to construct
            // a default instance of T, we can't support it here. once implemented, remove this special case to the test
            // and drop the try/catch from DebugComponent ctor.
            Assert.That(
                debugEntities[0].Components[0].Data,
                Is.InstanceOf <Exception>().With.Message.Match("Implement TypeManager.*DefaultValue"));
            #else
            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity, new DebugComponent {
                    Type = typeof(EcsTestSharedTag), Data = new EcsTestSharedTag()
                }) },
                debugEntities);
            #endif
        }
Esempio n. 5
0
        public void GetAllEntities_WithSharedComponentData()
        {
            var entity = m_Manager.CreateEntity();

            m_Manager.AddSharedComponentData(entity, new EcsTestSharedComp(5));

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(EcsTestSharedComp), Data = new EcsTestSharedComp(5)
                }) },
                debugEntities);

            EntitiesAssert.AreNotEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(EcsTestSharedComp), Data = new EcsTestSharedComp(6)
                }) },
                debugEntities);
        }
Esempio n. 6
0
        public void GetAllEntities_WithComponentObject()
        {
            var entity    = m_Manager.CreateEntity();
            var component = new TestClassComponent {
                Value = 5
            };

            m_Manager.AddComponentObject(entity, component);

            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(TestClassComponent), Data = component
                }) },
                debugEntities);

            // currently we are doing Equals comparisons, so validate it
            EntitiesAssert.AreEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(TestClassComponent), Data = new TestClassComponent {
                        Value = 5
                    }
                }) },
                debugEntities);
            EntitiesAssert.AreNotEqual(
                new[] { new DebugEntity(entity,
                                        new DebugComponent {
                    Type = typeof(TestClassComponent), Data = new TestClassComponent {
                        Value = 6
                    }
                }) },
                debugEntities);
        }
        static void Contains(EntityManager entityManager, IEnumerable <EntityMatch> matchers, bool only)
        {
            var entitiesList = DebugEntity
                               .GetAllEntities(entityManager)
                               .Select((e, i) => (e, mi: -1))
                               .ToList();
            var matchersList = matchers
                               .Select((m, i) => (m, ei: -1))
                               .ToList();

            var(remainingEntities, remainingMatchers) = (entitiesList.Count, matchersList.Count);
            for (var ei = 0; ei < entitiesList.Count; ++ei)
            {
                var entity = entitiesList[ei].e;

                for (var mi = 0; mi < matchersList.Count; ++mi)
                {
                    var matcher = matchersList[mi];
                    if (matcher.ei < 0 && matcher.m.IsMatch(entity))
                    {
                        matchersList[mi] = (matcher.m, ei);
                        entitiesList[ei] = (entity, mi);
                        --remainingEntities;
                        --remainingMatchers;
                        break;
                    }
                }
            }

            var fail = false;

            if (remainingMatchers > 0)
            {
                fail = true;
            }
            else if (only && remainingEntities > 0)
            {
                fail = true;
            }

            if (fail)
            {
                var sb = new StringBuilder();
                sb.AppendLine("Entities do not match exactly what is expected");
                sb.AppendLine();

                sb.AppendLine("Matchers");
                for (var mi = 0; mi < matchersList.Count; ++mi)
                {
                    var ei = matchersList[mi].ei;
                    var es = ei < 0 ? '?' : (char)(ei + 'a');
                    sb.AppendLine($"  {mi}»{es} - {matchersList[mi].m.Desc}");
                }
                sb.AppendLine();

                sb.AppendLine("Entities");
                for (var ei = 0; ei < entitiesList.Count; ++ei)
                {
                    var mi         = entitiesList[ei].mi;
                    var ms         = mi < 0 ? "?" : mi.ToString();
                    var entity     = entitiesList[ei].e;
                    var components = string.Join(", ", entity.Components.Select(c => c.ToString(20)).OrderBy(_ => _));
                    sb.AppendLine($"  {(char)(ei + 'a')}»{ms} - {entity.Entity} <{components}>");
                }
                sb.AppendLine();

                throw new AssertionException(sb.ToString());
            }
        }
Esempio n. 8
0
        public void GetAllEntities_WithEmptyEcs()
        {
            var debugEntities = DebugEntity.GetAllEntities(m_Manager);

            CollectionAssert.IsEmpty(debugEntities);
        }