summaryrefslogtreecommitdiff
path: root/GameCode/MenuControllerHandler.cs
blob: 4f399bd26d25b9ff38b7fe28d762b4fcaeb2c280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using InControl;
using UnityEngine;
using UnityEngine.EventSystems;

public class MenuControllerHandler : MonoBehaviour
{
	public enum MenuControl
	{
		Controller,
		Mouse,
		Unassigned
	}

	public static MenuControl menuControl;

	public MenuControl lastMenuControl;

	public Action<MenuControl> switchControlAction;

	public static MenuControllerHandler instance;

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		Switch();
	}

	private void Update()
	{
		if (Input.GetKeyDown(KeyCode.Mouse0))
		{
			menuControl = MenuControl.Mouse;
		}
		if (Input.GetKeyDown(KeyCode.Mouse1))
		{
			menuControl = MenuControl.Mouse;
		}
		for (int i = 0; i < InputManager.ActiveDevices.Count; i++)
		{
			InputDevice inputDevice = InputManager.ActiveDevices[i];
			if (!inputDevice.AnyButtonWasPressed && !(Mathf.Abs(inputDevice.LeftStick.Value.y) > 0.1f))
			{
				continue;
			}
			menuControl = MenuControl.Controller;
			if (EventSystem.current.currentSelectedGameObject.activeInHierarchy)
			{
				continue;
			}
			ListMenuButton[] array = UnityEngine.Object.FindObjectsOfType<ListMenuButton>();
			for (int j = 0; j < array.Length; j++)
			{
				if (array[j].enabled)
				{
					ListMenu.instance.SelectButton(array[j]);
				}
			}
		}
		if (menuControl != lastMenuControl)
		{
			Switch();
		}
		lastMenuControl = menuControl;
	}

	private void Switch()
	{
		switchControlAction?.Invoke(menuControl);
	}
}