Esempio n. 1
0
        public override void OnFixedUpdate()
        {
            _updatesCounter++;
            _transformComponent.Translation = _transformComponent.Translation.WithY(Math.Sin(_updatesCounter * 0.1) * 10);

            if (_inputComponent.GetActionState("Flap") && _updatesCounter > 30)
            {
                Debug.Assert(Entity != null, nameof(Entity) + " != null");

                Entity.RemoveComponent(this);
                Entity.AddComponent(new BirdPhysicsComponent());
                Entity.AddComponent(new BirdPlayerControlsComponent());
            }
        }
        public void GetActionState_ShouldReturnActionState()
        {
            // Arrange
            var inputComponent = new InputComponent();

            const string actionName  = "ActionName";
            const bool   actionState = true;

            inputComponent.ActionStates[actionName] = actionState;

            // Act
            var actual = inputComponent.GetActionState(actionName);

            // Assert
            Assert.That(actual, Is.EqualTo(actionState));
        }
Esempio n. 3
0
        private static void HandleActionMappings(InputComponent inputComponent)
        {
            var previousActionStates = new Dictionary <string, bool>(inputComponent.ActionStates);

            ResetActionStates(inputComponent);
            if (inputComponent.InputMapping == null)
            {
                return;
            }

            var actionMappings = inputComponent.InputMapping.ActionMappings;

            foreach (var actionMapping in actionMappings)
            {
                var actionName = actionMapping.ActionName;

                foreach (var hardwareAction in actionMapping.HardwareActions)
                {
                    var state = ComputeState(inputComponent.HardwareInput, hardwareAction);
                    inputComponent.ActionStates[actionName] = state;
                    if (state)
                    {
                        break;
                    }
                }

                if (inputComponent.ActionBindings.ContainsKey(actionName))
                {
                    previousActionStates.TryGetValue(actionName, out var previousActionState);

                    if (previousActionState == false && inputComponent.GetActionState(actionName))
                    {
                        inputComponent.ActionBindings[actionName]();
                    }
                }
            }
        }