using System; using System.Collections.Generic; using Core; using UnityEngine; public class UIKeyInput : MonoBehaviour { public static GameObject HoveredObject { get { return UICamera.hoveredObject; } set { UICamera.hoveredObject = value; UIKeyInput._hoveredButtonNavigation = ((!(value != null)) ? null : value.GetComponent()); } } public static void SaveHoveredObject() { UIKeyInput.LastHoveredObjects.Push(UIKeyInput.HoveredObject); } public static void SaveAndSetHoveredObject(GameObject gameObject) { UIKeyInput.SaveHoveredObject(); UIKeyInput.HoveredObject = gameObject; } public static void LoadHoveredObject() { UIKeyInput.HoveredObject = ((UIKeyInput.LastHoveredObjects.Count == 0) ? null : UIKeyInput.LastHoveredObjects.Pop()); } private void Update() { this.UpdateInput(); this.UpdateButtonNavigation(); } private void UpdateButtonNavigation() { UIButtonNavigation uibuttonNavigation = (!(UIKeyInput.HoveredObject != null)) ? null : UIKeyInput._hoveredButtonNavigation; if (uibuttonNavigation != null) { if (uibuttonNavigation.button.state != UIButtonColor.State.Pressed) { uibuttonNavigation.button.state = UIButtonColor.State.Pressed; } uibuttonNavigation.OnNavigate(); if (R.Mode.IsInUIMode() && UnityEngine.Input.GetKeyDown(KeyCode.Tab)) { uibuttonNavigation.OnKey(KeyCode.Tab); } } } private void UpdateInput() { if (Core.Input.UI.Pause.OnClick || Core.Input.Shi.Pause.OnClick) { UIKeyInput.OnPauseClick(); } if (Core.Input.UI.Debug.OnClick && UnityEngine.Debug.isDebugBuild) { this.OnDebugClick(); } } public static YieldInstruction OnPauseClick() { UIKeyInput._pauseButtonClickCount++; if (UIKeyInput._pauseButtonClickCount % 2 != 0) { return R.Ui.Pause.PauseThenOpenWithAnim(); } return R.Ui.Pause.CloseWithAnimThenResume(); } public void OnDebugClick() { this._debugButtonClickCount++; if (this._debugButtonClickCount % 2 != 0) { SingletonMono.Instance.Open(); } else { SingletonMono.Instance.Close(); } } private void OnApplicationPause(bool pause) { if (!pause && R.Ui.Pause.Enabled && !WorldTime.IsPausing) { UIKeyInput.OnPauseClick(); } } private static readonly Stack LastHoveredObjects = new Stack(); private static UIButtonNavigation _hoveredButtonNavigation; private static int _pauseButtonClickCount; private int _debugButtonClickCount; }