summaryrefslogtreecommitdiff
path: root/GameCode/MenuControllerHandler.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/MenuControllerHandler.cs
+ init
Diffstat (limited to 'GameCode/MenuControllerHandler.cs')
-rw-r--r--GameCode/MenuControllerHandler.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/GameCode/MenuControllerHandler.cs b/GameCode/MenuControllerHandler.cs
new file mode 100644
index 0000000..4f399bd
--- /dev/null
+++ b/GameCode/MenuControllerHandler.cs
@@ -0,0 +1,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);
+ }
+}