示例#1
0
        public void GroupInvokesOnEntityUpdatedWhenReplacingAComponent()
        {
            SetupGroupEntities();

            var updated = 0;

            var prevComp = eA.GetComponent(MyTestComponentsLookup.ComponentA);
            var newComp  = new ComponentA();
            var g        = _defaultContext.GetGroup(Matcher <MyTestEntity> .AllOf(MyTestComponentsLookup.ComponentA));

            g.OnEntityUpdated += (group, entity, index, previousComponent, newComponent) =>
            {
                updated += 1;

                Assert.AreEqual(g, group);
                Assert.AreEqual(eA, entity);
                Assert.AreEqual(MyTestComponentsLookup.ComponentA, index);
                Assert.AreEqual(prevComp, previousComponent);
                Assert.AreEqual(newComp, newComponent);
            };

            eA.ReplaceComponent(MyTestComponentsLookup.ComponentA, newComp);

            Assert.AreEqual(1, updated);
        }
示例#2
0
        public void CopiesOfAllComponentsAddedToTargetEntity()
        {
            _originalEntity.AddComponentA();
            _originalEntity.AddComponent(MyTestComponentsLookup.NameAge, _nameAge);
            _originalEntity.CopyTo(_targetEntity);

            Assert.AreEqual(2, _targetEntity.GetComponents().Length);
            Assert.IsTrue(_targetEntity.HasComponentA());
            Assert.IsTrue(_targetEntity.HasNameAge);
            Assert.AreNotEqual(Component.A, _targetEntity.GetComponentA());
            Assert.AreNotEqual(_nameAge, _targetEntity.NameAge);

            var clonedComponent = (NameAgeComponent)_targetEntity.GetComponent(MyTestComponentsLookup.NameAge);

            Assert.AreEqual(_nameAge.name, clonedComponent.name);
            Assert.AreEqual(_nameAge.age, clonedComponent.age);
        }
        public void CopiesOfAllComponentsAddedToTargetEntity()
        {
            _entity.AddComponentA();
            _entity.AddComponent(CID.ComponentB, _nameAge);

#pragma warning disable CS0618  // Type or member is obsolete
#pragma warning disable HAA0101 // Array allocation for params parameter
            _entity.CopyTo(_target);
#pragma warning restore HAA0101 // Array allocation for params parameter
#pragma warning restore CS0618  // Type or member is obsolete

            Assert.AreEqual(2, _target.GetComponents().Length);
            Assert.IsTrue(_target.HasComponentA());
            Assert.IsTrue(_target.HasComponentB());
            Assert.AreNotEqual(Component.A, _target.GetComponentA());
            Assert.AreNotEqual(_nameAge, _target.GetComponent(CID.ComponentB));

            var clonedComponent = (NameAgeComponent)_target.GetComponent(CID.ComponentB);

            Assert.AreEqual(_nameAge.name, clonedComponent.name);
            Assert.AreEqual(_nameAge.age, clonedComponent.age);
        }