Exemplo n.º 1
0
    private void Update()
    {
        Actions.Clear();
        ActionsDown.Clear();
        ActionsUp.Clear();

        Axis    = new Vector2(Input.GetAxis(InputAxesLiterals.Horizontal), Input.GetAxis(InputAxesLiterals.Vertical));
        RawAxis = new Vector2(Input.GetAxisRaw(InputAxesLiterals.Horizontal), Input.GetAxisRaw(InputAxesLiterals.Vertical));

        Touches = Input.touches;

        MousePosition    = Input.mousePosition;
        MouseScrollDelta = Input.mouseScrollDelta;

        _inputContext.InputItems.ForEach(ResolveInput);
    }
Exemplo n.º 2
0
    private void ResolveInput(InputMap inputMap)
    {
        // Keyboard
        if (Input.GetKeyDown(inputMap.KeyCode))
        {
            ActionsDown.Add(inputMap.Action);
            return;
        }

        if (Input.GetKeyUp(inputMap.KeyCode))
        {
            ActionsUp.Add(inputMap.Action);
            return;
        }

        if (Input.GetKey(inputMap.KeyCode))
        {
            Actions.Add(inputMap.Action);
            return;
        }

        // Touch
        if (inputMap.Touch && Input.touchCount > 0)
        {
            var firstTouch = Input.GetTouch(0);
            switch (firstTouch.phase)
            {
            case TouchPhase.Moved:
            case TouchPhase.Stationary:
                Actions.Add(inputMap.Action);
                return;

            case TouchPhase.Began:
                ActionsDown.Add(inputMap.Action);
                return;

            case TouchPhase.Ended:
                ActionsUp.Add(inputMap.Action);
                return;
            }
        }

        // Mouse
        if (Input.GetMouseButtonDown((int)inputMap.MouseButton))
        {
            ActionsDown.Add(inputMap.Action);
            return;
        }

        if (Input.GetMouseButtonUp((int)inputMap.MouseButton))
        {
            ActionsUp.Add(inputMap.Action);
            return;
        }

        if (Input.GetMouseButton((int)inputMap.MouseButton))
        {
            Actions.Add(inputMap.Action);
            return;
        }
    }
Exemplo n.º 3
0
 public void EatActionEvent(string actionLiteral)
 {
     Actions.Remove(actionLiteral);
     ActionsDown.Remove(actionLiteral);
     ActionsUp.Remove(actionLiteral);
 }
Exemplo n.º 4
0
 public bool GetActionDown(string actionLiteral)
 {
     return(ActionsDown.Any(action => action == actionLiteral));
 }