From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/MenuControllerHandler.cs | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 GameCode/MenuControllerHandler.cs (limited to 'GameCode/MenuControllerHandler.cs') 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 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(); + 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); + } +} -- cgit v1.1-26-g67d0