UIDebug.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UIDebug : SingletonMono<UIDebug>
  5. {
  6. private void Awake()
  7. {
  8. UIDebug._table = this.debugWidget.transform.GetChild(0);
  9. UIDebug.debugBtns = new Dictionary<int, GameObject>();
  10. }
  11. public static int Register(string name, EventDelegate.Callback open)
  12. {
  13. int firstNotInUseId = UIDebug.GetFirstNotInUseId();
  14. Transform transform;
  15. if (firstNotInUseId == 0)
  16. {
  17. transform = UIDebug._table.GetChild(0);
  18. }
  19. else
  20. {
  21. transform = UnityEngine.Object.Instantiate<Transform>(UIDebug._table.GetChild(0));
  22. transform.parent = UIDebug._table;
  23. transform.localScale = Vector3.one;
  24. }
  25. UIDebug.debugBtns.Add(firstNotInUseId, transform.gameObject);
  26. NGUITools.SetActive(transform.gameObject, true);
  27. UIButton component = transform.GetChild(0).GetComponent<UIButton>();
  28. UILabel component2 = transform.GetChild(1).GetComponent<UILabel>();
  29. component2.text = name;
  30. EventDelegate.Set(component.onClick, open);
  31. return firstNotInUseId;
  32. }
  33. public static void Unregister(int id)
  34. {
  35. UnityEngine.Object.Destroy(UIDebug.debugBtns[id]);
  36. UIDebug.debugBtns.Remove(id);
  37. }
  38. private static int GetFirstNotInUseId()
  39. {
  40. for (int i = 0; i < UIDebug.debugBtns.Count; i++)
  41. {
  42. if (!UIDebug.debugBtns.ContainsKey(i))
  43. {
  44. return i;
  45. }
  46. }
  47. return UIDebug.debugBtns.Count;
  48. }
  49. public void Open()
  50. {
  51. UIDebug.IsVisible = true;
  52. R.Mode.EnterMode(Mode.AllMode.UI);
  53. R.Ui.Pause.Enabled = false;
  54. R.PauseGame();
  55. this.debugWidget.gameObject.SetActive(true);
  56. Cursor.visible = true;
  57. Cursor.SetCursor(this._cursor, Vector2.zero, CursorMode.Auto);
  58. }
  59. public void Close()
  60. {
  61. UIDebug.IsVisible = false;
  62. R.Mode.ExitMode(Mode.AllMode.UI);
  63. R.Ui.Pause.Enabled = true;
  64. R.ResumeGame();
  65. this.debugWidget.gameObject.SetActive(false);
  66. }
  67. public static bool IsVisible;
  68. [SerializeField]
  69. private UIWidget debugWidget;
  70. private static Transform _table;
  71. [SerializeField]
  72. private Texture2D _cursor;
  73. private static Dictionary<int, GameObject> debugBtns;
  74. }