예제 #1
0
        public void AddComponent_AddsComponentToEntityAndContainer()
        {
            var entity    = new Mock <IEntity>(MockBehavior.Strict);
            var component = new Mock <IScriptComponent>();

            entity.Setup(_ => _.AddComponent(component.Object));

            _target.AddComponent(entity.Object, component.Object);

            Assert.IsTrue(_target.GetComponents <IScriptComponent>().Any());
            Assert.IsTrue(_target.GetEntitiesWithComponent <IScriptComponent>().Any());
            entity.Verify(_ => _.AddComponent(component.Object), Times.Once);
        }
예제 #2
0
        public void PlaySounds_WhenActiveListener_SetsListenerProperties()
        {
            _mockListener.SetupSet(_ => _.Gain     = It.IsAny <float>());
            _mockListener.SetupSet(_ => _.Position = It.IsAny <Vector3>());
            _mockListener.SetupSet(_ => _.Velocity = It.IsAny <Vector3>());

            var listener = _entityContainer.CreateEntity();

            _entityContainer.AddComponent(listener, new ListenerComponent {
                Active = true
            });
            _entityContainer.AddComponent(listener, new PositionComponent {
                Position = new Vector3(3, 4, 5)
            });
            _entityContainer.AddComponent(listener, new PhysicsComponent {
                Velocity = new Vector3(1, 2, 3)
            });

            _target.PlaySounds(_entityContainer);

            _mockListener.VerifySet(_ => _.Gain     = 1);
            _mockListener.VerifySet(_ => _.Position = new Vector3(3, 4, 5));
            _mockListener.VerifySet(_ => _.Velocity = new Vector3(1, 2, 3));
        }
예제 #3
0
        public void Simulate_GravityMovesEntityDown()
        {
            var entity   = _entityContainer.CreateEntity();
            var position = new PositionComponent();

            _entityContainer.AddComponent(entity, position);
            _entityContainer.AddComponent(entity, new PhysicsComponent());

            _target.Gravity = new Vector3(0, -100, 0);
            _target.Simulate(1, _entityContainer);

            Assert.AreEqual(-75, position.Position.Y);
        }