Example #1
0
    private bool IsDeviceUsable(InputDevice device, PlayerControls playerControls)
    {
        InputActionAsset actions = playerControls.asset;

        if (actions.controlSchemes.Count > 0)
        {
            if (!(InputUser.GetUnpairedInputDevices().Contains(device)))
            {
                return(false);
            }

            if (InputControlScheme.FindControlSchemeForDevice(device, actions.controlSchemes) == null)
            {
                return(false);
            }


            return(true);
        }

        // This is so if there are no controlSchemes, it checks whether the device can be used with the actionMap.
        foreach (var actionMap in actions.actionMaps)
        {
            if (actionMap.IsUsableWithDevice(device))
            {
                return(true);
            }
        }

        return(false);
    }
Example #2
0
    public void OnTrusters(InputAction.CallbackContext context)
    {
        var device = context.control.device;
        var scheme = InputControlScheme.FindControlSchemeForDevice(device, context.action.actionMap.controlSchemes);
        if (scheme.HasValue)
        {
            _uiManager.updateButtonImage(scheme.Value.name);
        }
        else

        {
            _uiManager.updateButtonImage("none");
        }

        _isPressed = context.ReadValue<float>();
    }
Example #3
0
    public void OnMovement(InputAction.CallbackContext context)
    {
        var device = context.control.device;
        var scheme = InputControlScheme.FindControlSchemeForDevice(device, context.action.actionMap.controlSchemes);
        if (scheme.HasValue)
        {
            _uiManager.updateButtonImage(scheme.Value.name);
        }
        else

        {
            _uiManager.updateButtonImage("none");
        }

        moveDirection = context.ReadValue<Vector2>();
    }
 public void Refresh()
 {
     if (useInputActionAsset)
     {
         if (inputActionMap != null && GameManager.Instance.lastDetectedDevice != null)
         {
             var scheme = InputControlScheme.FindControlSchemeForDevice(GameManager.Instance.lastDetectedDevice,
                                                                        inputActionMap.controlSchemes);
             if (scheme.HasValue)
             {
                 OnControlSchemeChanged(scheme.Value.name);
             }
         }
     }
     else if (playerInput)
     {
         OnControlSchemeChanged(playerInput.currentControlScheme);
     }
 }
Example #5
0
    public void OnFire(InputAction.CallbackContext context)
    {
        var device = context.control.device;
        var scheme = InputControlScheme.FindControlSchemeForDevice(device, context.action.actionMap.controlSchemes);
        if (scheme.HasValue)
        {
            _uiManager.updateButtonImage(scheme.Value.name);
        }
        else

        {
            _uiManager.updateButtonImage("none");
        }
        if (Time.timeScale != 0)
        {
            if (context.performed && Time.time > _canFire)
            {
                shootLaser();
            }
        }
    }
Example #6
0
    public void OnPickUpCollect(InputAction.CallbackContext context)
    {
        var device = context.control.device;
        var scheme = InputControlScheme.FindControlSchemeForDevice(device, context.action.actionMap.controlSchemes);
        if (scheme.HasValue)
        {
            _uiManager.updateButtonImage(scheme.Value.name);
        }
        else

        {
            _uiManager.updateButtonImage("none");
        }

        float _keyPressed = context.ReadValue<float>();
        if (_keyPressed == 1)
        {
            GameObject[] powerUps = GameObject.FindGameObjectsWithTag("powerUp");
            GameObject[] enemyLaser = GameObject.FindGameObjectsWithTag("EnemyLaser");
            foreach (GameObject powerUp in powerUps)
            {
                powerUp.SendMessage("CollectPowerupPressed", (Vector2)transform.position);
            }
            foreach (GameObject powerUp in enemyLaser)
            {
                powerUp.SendMessage("CollectPowerupPressed", (Vector2)transform.position);
            }
        }
        else
        {
            GameObject[] powerUps = GameObject.FindGameObjectsWithTag("powerUp");
            foreach (GameObject powerUp in powerUps)
            {
                powerUp.SendMessage("CollectPowerupNotPressed");
            }
        }
    }
Example #7
0
 /// <summary>
 /// Based on the choice of the given device, select an appropriate control scheme.
 /// </summary>
 /// <param name="device"></param>
 /// <returns></returns>
 /// <remarks>
 /// The chosen control scheme may depend also on what other devices are already in use by other
 /// players.
 /// </remarks>
 public InputControlScheme?SelectControlSchemeBasedOnDevice(InputDevice device)
 {
     return(InputControlScheme.FindControlSchemeForDevice(device, controls.controlSchemes));
 }