Inheritance: MonoBehaviour
Beispiel #1
0
        public void Add_ManyComponents()
        {
            var entity = new EcsEntity();

            var component1 = new  TestComponent1();
            var component2 = new  TestComponent2();

            entity
            .AddComponent(component1)
            .AddComponent(component2);

            _ecsStoreService.AddEntity(entity);

            var actualEntity = _ecsStore.Entities.FirstOrDefault();

            Assert.AreEqual(_ecsStore.Entities.Count, 1);
            Assert.AreEqual(entity, actualEntity.Value);

            var entityByComponent1 = _ecsStore.EntitiesByComponents[typeof(TestComponent1)]?.FirstOrDefault();
            var entityByComponent2 = _ecsStore.EntitiesByComponents[typeof(TestComponent2)]?.FirstOrDefault();

            Assert.AreEqual(entity, entityByComponent1);
            Assert.AreEqual(entity, entityByComponent2);

            Assert.AreEqual(2, _ecsStore.EntitiesByComponents.Count);
            Assert.AreEqual(1, _ecsStore.EntitiesByComponents[typeof(TestComponent1)].Count);
            Assert.AreEqual(1, _ecsStore.EntitiesByComponents[typeof(TestComponent2)].Count);
        }
Beispiel #2
0
        public void Add_AddComponentToExistingEntity()
        {
            var entity = new EcsEntity();

            var component1 = new  TestComponent1();
            var component2 = new  TestComponent2();

            entity.AddComponent(component1);

            _ecsStoreService.AddEntity(entity);

            Assert.AreEqual(1, _ecsStore.EntitiesByComponents.Count);

            entity.AddComponent(component2);

            Assert.AreEqual(2, _ecsStore.EntitiesByComponents.Count);
            Assert.AreEqual(1, _ecsStore.EntitiesByComponents[typeof(TestComponent1)].Count);
            Assert.AreEqual(1, _ecsStore.EntitiesByComponents[typeof(TestComponent2)].Count);

            var entityByComponent1 = _ecsStore.EntitiesByComponents[typeof(TestComponent1)]?.FirstOrDefault();
            var entityByComponent2 = _ecsStore.EntitiesByComponents[typeof(TestComponent2)]?.FirstOrDefault();

            Assert.AreEqual(entity, entityByComponent1);
            Assert.AreEqual(entity, entityByComponent2);
        }
Beispiel #3
0
        public AssetShould()
        {
            _component1 = new TestComponent1();
            _component2 = new TestComponent2();

            _actor = new Asset(1, new IComponent[] { _component1, _component2 });
        }
Beispiel #4
0
        public AssetFilter1Should()
        {
            _component1 = new TestComponent1();
            _component2 = new TestComponent2();
            InjectComponentsArray(new IComponent[] { _component1, _component2 });

            var assets = Fixture.CreateMany <Asset>().ToArray();

            _asset       = assets[0];
            _assetsCount = assets.Length;
            _assetFilter = new AssetFilter <TestComponent1>(assets);
        }
Beispiel #5
0
        public void TryGetComponentsTrue()
        {
            var component1 = new TestComponent1();
            var component2 = new TestComponent2();

            _actor.AddComponents(component1, component2);

            _actor
            .TryGetComponents <TestComponent1, TestComponent2>(out var exists1, out var exists2)
            .Should().BeTrue();

            exists1.Should().Be(component1);
            exists2.Should().Be(component2);
        }
Beispiel #6
0
        public void EntityGetComponents()
        {
            Engine engine = new Engine();

            Entity entity = engine.CreateEntity();

            TestComponent1 comp1 = new TestComponent1();
            TestComponent2 comp2 = new TestComponent2();

            entity.AddRawComponent(comp1);
            entity.AddRawComponent(comp2);

            Assert.IsTrue(entity.GetComponents().Contains(comp1));
            Assert.IsTrue(entity.GetComponents().Contains(comp2));
        }
        public void CanRegisterMultipleComponentsOnTheSameGameObjectForTargettedDelivery()
        {
            var gameObject = new GameObject();
            var testComponent = new TestComponent();
            var testComponent2 = new TestComponent2();

            gameObject.AddComponent(testComponent);
            gameObject.AddComponent(testComponent2);

            Scene.Current.AddObject(gameObject);

            gameObject.SendMessage(new TestGameMessage(), gameObject);

            Assert.True(testComponent.MessageHandled);
            Assert.True(testComponent2.MessageHandled);
        }
        public void CanRegisterMultipleComponentsOnTheSameGameObjectForTargettedDelivery()
        {
            var gameObject     = new GameObject();
            var testComponent  = new TestComponent();
            var testComponent2 = new TestComponent2();

            gameObject.AddComponent(testComponent);
            gameObject.AddComponent(testComponent2);

            Scene.Current.AddObject(gameObject);

            gameObject.SendMessage(new TestGameMessage(), gameObject);

            Assert.True(testComponent.MessageHandled);
            Assert.True(testComponent2.MessageHandled);
        }