123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class UINavigation
- {
- private static int count;
- public static List<UiBase> History;
- public static List<UiBase> PopHistory;
- public static void Init()
- {
- if(History != null || PopHistory != null)
- {
- return;
- }
- History = new List<UiBase>();
- PopHistory = new List<UiBase>();
- }
- public static void Clear()
- {
- History.Clear();
- PopHistory.Clear();
- }
- public static void AddItem(UiBase view)
- {
- if (view == null)
- return;
- if (view.needNavigation)
- {
- //弹出窗体后面的窗体冻结
- UiBase lastView = GetLastItem();
- if (lastView != null)
- lastView.Freeze();
- History.Add(view);
- }
- if (view.needPopNavigation)
- {
- UiBase lastView = GetPopLastItem();
- if (lastView != null)
- lastView.Freeze();
- PopHistory.Add(view);
- }
- }
- public static void RemoveLastItem(UiBase view)
- {
- if (view == null)
- return;
- if (view.needNavigation)
- {
- //从栈中移除
- UiBase lastView = GetLastItem();
- if(lastView == view)
- {
- count = History.Count;
- if (count == 0)
- return;
- History.RemoveAt(count - 1);
- }
- }
- if (view.needPopNavigation)
- {
- UiBase lastView = GetPopLastItem();
- if (lastView == view)
- {
- count = PopHistory.Count;
- if (count == 0)
- return;
- PopHistory.RemoveAt(count - 1);
- }
- }
- }
- public static UiBase GetLastItem()
- {
- count = History.Count;
- if (count == 0)
- return null;
- UiBase data = History[count - 1];
- return data;
- }
- /// <summary>
- /// 找到上一个打开过后已关闭的界面
- /// </summary>
- /// <returns></returns>
- public static UiBase GetLastOpenView()
- {
- count = History.Count;
- if (count <=1)
- return null;
- UiBase data = History[count - 2];
- return data;
- }
- public static UiBase GetPopLastItem()
- {
- count = PopHistory.Count;
- if (count == 0)
- return null;
- UiBase data = PopHistory[count - 1];
- return data;
- }
- }
|