This repository has been archived on 2024-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
sota/RunningLateGame/Assets/Starter Assets/Runtime/Mobile/Scripts/Utilities/MobileDisableAutoSwitchControls.cs
Sc0rch-thinks 1df2624133 game: adding unity packages (2)
added ai navigaion, input system, postprocessing and adding the starter asset charactor controler
2024-07-28 13:34:47 +08:00

42 lines
1.2 KiB
C#

/*
The PlayerInput component has an auto-switch control scheme action that allows automatic changing of connected devices.
IE: Switching from Keyboard to Gamepad in-game.
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)
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.
This is fixed in Input System 1.1.
For the time-being; this script will disable a PlayerInput's auto switch control schemes; when project is built to mobile.
*/
using System;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
public class MobileDisableAutoSwitchControls : MonoBehaviour
{
#if ENABLE_INPUT_SYSTEM && (UNITY_IOS || UNITY_ANDROID)
[Header("Target")]
public PlayerInput playerInput;
void Start()
{
DisableAutoSwitchControls();
}
void DisableAutoSwitchControls()
{
playerInput.neverAutoSwitchControlSchemes = true;
}
private void Update()
{
Debug.Log(playerInput.currentControlScheme);
}
#endif
}