UIKeyInput.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using Core;
  4. using UnityEngine;
  5. public class UIKeyInput : MonoBehaviour
  6. {
  7. public static GameObject HoveredObject
  8. {
  9. get
  10. {
  11. return UICamera.hoveredObject;
  12. }
  13. set
  14. {
  15. UICamera.hoveredObject = value;
  16. UIKeyInput._hoveredButtonNavigation = ((!(value != null)) ? null : value.GetComponent<UIButtonNavigation>());
  17. }
  18. }
  19. public static void SaveHoveredObject()
  20. {
  21. UIKeyInput.LastHoveredObjects.Push(UIKeyInput.HoveredObject);
  22. }
  23. public static void SaveAndSetHoveredObject(GameObject gameObject)
  24. {
  25. UIKeyInput.SaveHoveredObject();
  26. UIKeyInput.HoveredObject = gameObject;
  27. }
  28. public static void LoadHoveredObject()
  29. {
  30. UIKeyInput.HoveredObject = ((UIKeyInput.LastHoveredObjects.Count == 0) ? null : UIKeyInput.LastHoveredObjects.Pop());
  31. }
  32. private void Update()
  33. {
  34. this.UpdateInput();
  35. this.UpdateButtonNavigation();
  36. }
  37. private void UpdateButtonNavigation()
  38. {
  39. UIButtonNavigation uibuttonNavigation = (!(UIKeyInput.HoveredObject != null)) ? null : UIKeyInput._hoveredButtonNavigation;
  40. if (uibuttonNavigation != null)
  41. {
  42. if (uibuttonNavigation.button.state != UIButtonColor.State.Pressed)
  43. {
  44. uibuttonNavigation.button.state = UIButtonColor.State.Pressed;
  45. }
  46. uibuttonNavigation.OnNavigate();
  47. if (R.Mode.IsInUIMode() && UnityEngine.Input.GetKeyDown(KeyCode.Tab))
  48. {
  49. uibuttonNavigation.OnKey(KeyCode.Tab);
  50. }
  51. }
  52. }
  53. private void UpdateInput()
  54. {
  55. if (Core.Input.UI.Pause.OnClick || Core.Input.Shi.Pause.OnClick)
  56. {
  57. UIKeyInput.OnPauseClick();
  58. }
  59. if (Core.Input.UI.Debug.OnClick && UnityEngine.Debug.isDebugBuild)
  60. {
  61. this.OnDebugClick();
  62. }
  63. }
  64. public static YieldInstruction OnPauseClick()
  65. {
  66. UIKeyInput._pauseButtonClickCount++;
  67. if (UIKeyInput._pauseButtonClickCount % 2 != 0)
  68. {
  69. return R.Ui.Pause.PauseThenOpenWithAnim();
  70. }
  71. return R.Ui.Pause.CloseWithAnimThenResume();
  72. }
  73. public void OnDebugClick()
  74. {
  75. this._debugButtonClickCount++;
  76. if (this._debugButtonClickCount % 2 != 0)
  77. {
  78. SingletonMono<UIDebug>.Instance.Open();
  79. }
  80. else
  81. {
  82. SingletonMono<UIDebug>.Instance.Close();
  83. }
  84. }
  85. private void OnApplicationPause(bool pause)
  86. {
  87. if (!pause && R.Ui.Pause.Enabled && !WorldTime.IsPausing)
  88. {
  89. UIKeyInput.OnPauseClick();
  90. }
  91. }
  92. private static readonly Stack<GameObject> LastHoveredObjects = new Stack<GameObject>();
  93. private static UIButtonNavigation _hoveredButtonNavigation;
  94. private static int _pauseButtonClickCount;
  95. private int _debugButtonClickCount;
  96. }