Skip to content

Commit be6ab92

Browse files
author
JasonNumberThirteen
committed
Fix null values about a gamepad on WebGL platform
1 parent 73b7560 commit be6ab92

2 files changed

Lines changed: 1 addition & 31 deletions

File tree

Assets/Game/Scripts/MenuOptionsInputController.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class MenuOptionsInputController : MonoBehaviour
1313

1414
private int navigationDirection;
1515
private Timer timer;
16-
private PlayerInput playerInput;
1716

1817
public void SetActive(bool active)
1918
{
@@ -23,19 +22,10 @@ public void SetActive(bool active)
2322
private void Awake()
2423
{
2524
timer = GetComponent<Timer>();
26-
playerInput = GetComponent<PlayerInput>();
27-
28-
SetControlScheme();
25+
2926
RegisterToListeners(true);
3027
}
3128

32-
private void SetControlScheme()
33-
{
34-
var controlSchemeName = InputMethods.GamepadIsAvailable() ? InputMethods.GAMEPAD_CONTROL_SCHEME_NAME : InputMethods.KEYBOARD_AND_MOUSE_CONTROL_SCHEME_NAME;
35-
36-
InputMethods.SetControlSchemeToPlayerInputIfPossible(playerInput, controlSchemeName);
37-
}
38-
3929
private void OnDestroy()
4030
{
4131
RegisterToListeners(false);
Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
1-
using System.Collections.Generic;
21
using UnityEngine.InputSystem;
32

43
public static class InputMethods
54
{
6-
public static readonly string KEYBOARD_AND_MOUSE_CONTROL_SCHEME_NAME = "Keyboard&Mouse";
7-
public static readonly string GAMEPAD_CONTROL_SCHEME_NAME = "Gamepad";
8-
9-
private static readonly Dictionary<string, InputDevice[]> inputDevicesByControlSchemeName = new()
10-
{
11-
{KEYBOARD_AND_MOUSE_CONTROL_SCHEME_NAME, new InputDevice[]{Keyboard.current, Mouse.current}},
12-
{GAMEPAD_CONTROL_SCHEME_NAME, new InputDevice[]{Gamepad.current}}
13-
};
14-
155
public static bool GamepadIsAvailable() => Gamepad.current != null;
16-
17-
public static void SetControlSchemeToPlayerInputIfPossible(PlayerInput playerInput, string controlSchemeName)
18-
{
19-
if(playerInput != null && playerInput.user.valid)
20-
{
21-
playerInput.SwitchCurrentControlScheme(controlSchemeName, GetInputDevicesByControlSchemeName(controlSchemeName));
22-
}
23-
}
24-
25-
private static InputDevice[] GetInputDevicesByControlSchemeName(string controlSchemeName) => inputDevicesByControlSchemeName.TryGetValue(controlSchemeName, out var inputDevices) ? inputDevices : new InputDevice[0];
266
}

0 commit comments

Comments
 (0)