UIPanelStack.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.Generic;
  2. namespace QFramework
  3. {
  4. /// <summary>
  5. /// UI 界面的堆栈
  6. /// </summary>
  7. public class UIPanelStack
  8. {
  9. private Stack<PanelInfo> mUIStack = new Stack<PanelInfo>();
  10. public void Push<T>() where T : UIPanel
  11. {
  12. Push(UIKit.GetPanel<T>());
  13. }
  14. public void Push(IPanel view)
  15. {
  16. if (view != null)
  17. {
  18. mUIStack.Push(view.Info);
  19. view.Close();
  20. var panelSearchKeys = PanelSearchKeys.Allocate();
  21. panelSearchKeys.GameObjName = view.Transform.name;
  22. UIManager.Instance.RemoveUI(panelSearchKeys);
  23. panelSearchKeys.Recycle2Cache();
  24. }
  25. }
  26. public void Pop()
  27. {
  28. var previousPanelInfo = mUIStack.Pop();
  29. var panelSearchKeys = PanelSearchKeys.Allocate();
  30. panelSearchKeys.GameObjName = previousPanelInfo.GameObjName;
  31. panelSearchKeys.Level = previousPanelInfo.Level;
  32. panelSearchKeys.UIData = previousPanelInfo.UIData;
  33. panelSearchKeys.AssetBundleName = previousPanelInfo.AssetBundleName;
  34. panelSearchKeys.PanelType = previousPanelInfo.PanelType;
  35. UIManager.Instance.OpenUI(panelSearchKeys);
  36. panelSearchKeys.Recycle2Cache();
  37. }
  38. }
  39. }