Ejemplo n.º 1
0
        public void GetComponentsTest()
        {
            FakeComponentA fakeComponentA1 = new FakeComponentA();
            FakeComponentA fakeComponentA2 = new FakeComponentA();
            FakeComponentA fakeComponentA3 = new FakeComponentA();

            FakeComponentB fakeComponentB1 = new FakeComponentB();
            FakeComponentB fakeComponentB2 = new FakeComponentB();

            m_component.AddComponent(fakeComponentB1);
            m_component.AddComponent(fakeComponentA1);
            m_component.AddComponent(fakeComponentA2);
            m_component.AddComponent(fakeComponentA3);
            m_component.AddComponent(fakeComponentB2);

            IComponent[] f  = m_component.GetComponents <FakeComponent>();
            IComponent[] fa = m_component.GetComponents <FakeComponentA>();
            IComponent[] fb = m_component.GetComponents <FakeComponentB>();

            Assert.IsNotNull(f);
            Assert.IsNotNull(fa);
            Assert.IsNotNull(fb);

            Assert.AreEqual(1, f.Length, $"There should only be 1 Component of type {typeof(FakeComponent).Name} in this entity.");
            Assert.AreEqual(3, fa.Length, $"There should only be 3 Components of type {typeof(FakeComponentA).Name} in this entity.");
            Assert.AreEqual(2, fb.Length, $"There should only be 2 Components of type {typeof(FakeComponentB).Name} in this entity.");

            // 1. we cannot actually assert the following because the InstanceID's are GUIDs which are not guaranteed to be generated in an ascending sequence,
            // 2. the keys (the Component InstanceID GUID's) used to keep track of components inside the Entities will not be in an ascending order.
            // 3. therefore any component returned from the GetComponents method may not be the one we expect if we base our assumption on the order they were added to the entity.

            //Assert.AreSame(fa[0], fakeComponentA_1);
            //Assert.AreSame(fa[1], fakeComponentA_2);
            //Assert.AreSame(fa[2], fakeComponentA_3);
            //Assert.AreSame(fb[0], fakeComponentB_1);
            //Assert.AreSame(fb[1], fakeComponentB_2);

            Assert.IsTrue(fa.Contains(fakeComponentA1));
            Assert.IsTrue(fa.Contains(fakeComponentA2));
            Assert.IsTrue(fa.Contains(fakeComponentA3));
            Assert.IsFalse(fa.Contains(fakeComponentB1));
            Assert.IsFalse(fa.Contains(fakeComponentB2));

            Assert.IsFalse(fb.Contains(fakeComponentA1));
            Assert.IsFalse(fb.Contains(fakeComponentA2));
            Assert.IsFalse(fb.Contains(fakeComponentA3));
            Assert.IsTrue(fb.Contains(fakeComponentB1));
            Assert.IsTrue(fb.Contains(fakeComponentB2));

            Assert.AreNotSame(fb, fa);
        }
Ejemplo n.º 2
0
        public void GetComponentTest()
        {
            FakeComponentA fakeComponentA = new FakeComponentA();
            FakeComponentB fakeComponentB = new FakeComponentB();

            m_root.AddComponent(fakeComponentB);
            m_root.AddComponent(fakeComponentA);

            IComponent fa = m_root.GetComponent <FakeComponentA>();
            IComponent fb = m_root.GetComponent <FakeComponentB>();

            Assert.IsNotNull(fa);
            Assert.IsNotNull(fb);

            Assert.AreSame(fa, fakeComponentA);
            Assert.AreSame(fb, fakeComponentB);
            Assert.AreNotSame(fb, fa);
        }
Ejemplo n.º 3
0
        public void GetComponents_Excluding_A_Single_Component()
        {
            FakeComponentA fakeComponentA1 = new FakeComponentA();
            FakeComponentA fakeComponentA2 = new FakeComponentA();
            FakeComponentA fakeComponentA3 = new FakeComponentA();

            FakeComponentB fakeComponentB1 = new FakeComponentB();
            FakeComponentB fakeComponentB2 = new FakeComponentB();

            m_root.AddComponent(fakeComponentA1);
            m_root.AddComponent(fakeComponentA2);
            m_root.AddComponent(fakeComponentA3);
            m_root.AddComponent(fakeComponentB1);
            m_root.AddComponent(fakeComponentB2);

            IComponent[] fa = m_root.GetComponents <FakeComponentB>(fakeComponentB1);

            Assert.IsNotNull(fa);
            Assert.AreEqual(1, fa.Length, $"There should only be 1 Component of type {typeof(FakeComponentB).Name} in this entity.");
            Assert.IsNotNull(fa[0]);
            Assert.AreSame(fakeComponentB2, fa[0]);
        }
Ejemplo n.º 4
0
        public void GetComponents_Excluding_Multiple_Components()
        {
            FakeComponentA fakeComponentA1 = new FakeComponentA();
            FakeComponentA fakeComponentA2 = new FakeComponentA();
            FakeComponentA fakeComponentA3 = new FakeComponentA();
            FakeComponentB fakeComponentB1 = new FakeComponentB();
            FakeComponentB fakeComponentB2 = new FakeComponentB();

            m_root.AddComponent(fakeComponentA1);
            m_root.AddComponent(fakeComponentB1);
            m_root.AddComponent(fakeComponentA2);
            m_root.AddComponent(fakeComponentA3);
            m_root.AddComponent(fakeComponentB2);

            IComponent[] fb = m_root.GetComponents <FakeComponentB>(new IComponent[] { fakeComponentA1, fakeComponentA3 });

            Assert.IsNotNull(fb);
            Assert.AreEqual(2, fb.Length, $"There should only be 2 Components of type {typeof(FakeComponentB).Name} in this entity.");
            Assert.IsNotNull(fb[0]);
            Assert.IsNotNull(fb[1]);
            Assert.IsTrue(fb.Contains(fakeComponentB1));
            Assert.IsTrue(fb.Contains(fakeComponentB2));
        }