Beispiel #1
0
 protected void FireTrigger(InputActionEvent actionEvent)
 {
     if (Trigger != null)
     {
         Trigger(this, actionEvent);
     }
 }
        public void HandleInput(InputActionEvent action)
        {
            if (action.Type == InputActionType.Held && action.Action == trigger)
            {
                if (!buttonDown)
                {
                    buttonDown          = true;
                    buttonDownTimestamp = Time.realtimeSinceStartup;
                }

                var time = Time.realtimeSinceStartup;

                if (time > buttonDownTimestamp + HoldActivateDelay)
                {
                    if (time > holdRepeatTimestamp + HoldRepeatDelay)
                    {
                        if (OnTrigger != null)
                        {
                            OnTrigger();
                        }

                        holdRepeatTimestamp = Time.realtimeSinceStartup;
                    }
                }
            }
            else
            {
                buttonDown = false;
            }
        }
Beispiel #3
0
 void IInputHandler.HandleInput(InputActionEvent action)
 {
     if (InputEnabled)
     {
         _inputHandlers.ForEach(x => x.HandleInput(action));
     }
 }
        public void LateUpdate()
        {
            foreach (var kvp in _bindings)
            {
                if (Input.anyKey)
                {
                    if (Input.GetKeyDown(kvp.Value))
                    {
                        var e = new InputActionEvent(kvp.Key, InputActionType.Down);
                        FireTrigger(e);
                    }

                    if (Input.GetKey(kvp.Value))
                    {
                        var e = new InputActionEvent(kvp.Key, InputActionType.Held);
                        FireTrigger(e);
                    }
                }

                if (Input.GetKeyUp(kvp.Value))
                {
                    var e = new InputActionEvent(kvp.Key, InputActionType.Up);
                    FireTrigger(e);
                }
            }

            _mouseX = Input.GetAxis("Mouse X");
            _mouseY = Input.GetAxis("Mouse Y");

            if (Mathf.Abs(_mouseX) > 0f)
            {
                FireTrigger(new InputActionEvent(Horizontal, InputActionType.Axis, _mouseX));
            }

            if (Mathf.Abs(_mouseY) > 0f)
            {
                FireTrigger(new InputActionEvent(Vertical, InputActionType.Axis, _mouseY));
            }

            if (Input.GetAxis("Mouse ScrollWheel") > 0f)
            {
                FireTrigger(new InputActionEvent(ScrollUp, InputActionType.Down));
            }

            if (Input.GetAxis("Mouse ScrollWheel") < 0f)
            {
                FireTrigger(new InputActionEvent(ScrollDown, InputActionType.Down));
            }

            if (Input.GetMouseButtonDown(0))
            {
                FireTrigger(new InputActionEvent(LeftClick, InputActionType.Down));
            }

            if (Input.GetMouseButtonDown(1))
            {
                FireTrigger(new InputActionEvent(RightClick, InputActionType.Down));
            }
        }
 void IInputHandler.HandleInput(InputActionEvent action)
 {
     if (action.Action == InputMap.Pause && action.Type == InputActionType.Down)
     {
         _stateManager.ToggleState();
         Debug.Log("Game is now " + _stateManager.State);
     }
 }
Beispiel #6
0
        private static void Relay(object sender, InputActionEvent action)
        {
            if (action.Context != context)
            {
                context = action.Context;
                contextHandlers.ForEach(x => x.HandleContextChange(context));
            }

            inputHandlers.ForEach(x => x.HandleInput(action));
        }
Beispiel #7
0
 public static void Trigger(InputActionEvent action)
 {
     Relay(null, action);
 }
 private static void Relay(object sender, InputActionEvent action)
 {
     handlers.ForEach(x => x.HandleInput(action));
 }