123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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<UIButtonNavigation>());
- }
- }
- 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<UIDebug>.Instance.Open();
- }
- else
- {
- SingletonMono<UIDebug>.Instance.Close();
- }
- }
- private void OnApplicationPause(bool pause)
- {
- if (!pause && R.Ui.Pause.Enabled && !WorldTime.IsPausing)
- {
- UIKeyInput.OnPauseClick();
- }
- }
- private static readonly Stack<GameObject> LastHoveredObjects = new Stack<GameObject>();
- private static UIButtonNavigation _hoveredButtonNavigation;
- private static int _pauseButtonClickCount;
- private int _debugButtonClickCount;
- }
|