MobileDisableAutoSwitchControls.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. The PlayerInput component has an auto-switch control scheme action that allows automatic changing of connected devices.
  3. IE: Switching from Keyboard to Gamepad in-game.
  4. When built to a mobile phone; in most cases, there is no concept of switching connected devices as controls are typically driven through what is on the device's hardware (Screen, Tilt, etc)
  5. In Input System 1.0.2, if the PlayerInput component has Auto Switch enabled, it will search the mobile device for connected devices; which is very costly and results in bad performance.
  6. This is fixed in Input System 1.1.
  7. For the time-being; this script will disable a PlayerInput's auto switch control schemes; when project is built to mobile.
  8. */
  9. using UnityEngine;
  10. #if ENABLE_INPUT_SYSTEM
  11. using UnityEngine.InputSystem;
  12. #endif
  13. public class MobileDisableAutoSwitchControls : MonoBehaviour
  14. {
  15. #if ENABLE_INPUT_SYSTEM && (UNITY_IOS || UNITY_ANDROID)
  16. [Header("Target")]
  17. public PlayerInput playerInput;
  18. void Start()
  19. {
  20. DisableAutoSwitchControls();
  21. }
  22. void DisableAutoSwitchControls()
  23. {
  24. playerInput.neverAutoSwitchControlSchemes = true;
  25. }
  26. #endif
  27. }