UIStackManager.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UIStackManager : MonoBehaviour
  5. {
  6. public List<UIWindowBase> m_normalStack = new List<UIWindowBase>();
  7. public List<UIWindowBase> m_fixedStack = new List<UIWindowBase>();
  8. public List<UIWindowBase> m_popupStack = new List<UIWindowBase>();
  9. public List<UIWindowBase> m_topBarStack = new List<UIWindowBase>();
  10. public void OnUIOpen(UIWindowBase ui)
  11. {
  12. switch (ui.m_UIType)
  13. {
  14. case UIType.Fixed: m_fixedStack.Add(ui); break;
  15. case UIType.Normal: m_normalStack.Add(ui); break;
  16. case UIType.PopUp: m_popupStack.Add(ui); break;
  17. case UIType.TopBar: m_topBarStack.Add(ui); break;
  18. }
  19. }
  20. public void OnUIClose(UIWindowBase ui)
  21. {
  22. switch (ui.m_UIType)
  23. {
  24. case UIType.Fixed: m_fixedStack.Remove(ui); break;
  25. case UIType.Normal: m_normalStack.Remove(ui); break;
  26. case UIType.PopUp: m_popupStack.Remove(ui); break;
  27. case UIType.TopBar: m_topBarStack.Remove(ui); break;
  28. }
  29. }
  30. public void CloseLastUIWindow(UIType uiType = UIType.Normal)
  31. {
  32. UIWindowBase ui = GetLastUI(uiType);
  33. if(ui != null)
  34. {
  35. UIManager.CloseUIWindow(ui);
  36. }
  37. }
  38. public UIWindowBase GetLastUI(UIType uiType)
  39. {
  40. switch (uiType)
  41. {
  42. case UIType.Fixed:
  43. if (m_fixedStack.Count > 0)
  44. return m_fixedStack[m_fixedStack.Count - 1];
  45. else
  46. return null;
  47. case UIType.Normal:
  48. if (m_normalStack.Count > 0)
  49. return m_normalStack[m_normalStack.Count - 1];
  50. else
  51. return null;
  52. case UIType.PopUp:
  53. if (m_popupStack.Count > 0)
  54. return m_popupStack[m_popupStack.Count - 1];
  55. else
  56. return null;
  57. case UIType.TopBar:
  58. if (m_topBarStack.Count > 0)
  59. return m_topBarStack[m_topBarStack.Count - 1];
  60. else
  61. return null;
  62. }
  63. throw new System.Exception("CloseLastUIWindow does not support GameUI");
  64. }
  65. }