| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 | 
							- using UnityEngine;
 
- using System.Collections.Generic;
 
- using System;
 
- using FairyGUI;
 
- using System.Linq;
 
- using ET;
 
- namespace GFGGame
 
- {
 
-     /// <summary>
 
-     /// ��ͼ������
 
-     /// ������ͼ����ʾ������
 
-     /// </summary>
 
-     public class ViewManager
 
-     {
 
-         private static Dictionary<string, IUIView> _viewDic;
 
-         private static GComponent _bottomLayer;
 
-         private static GComponent _topLayer;
 
-         private static GComponent _guideLayer;
 
-         private static GComponent _modalLayer;
 
-         private static GComponent _alertLayer;
 
-         private static GComponent _debugLayer;
 
-         private static GComponent _floatLayer;
 
-         private static Dictionary<string, List<object[]>> _goBackDatas = new Dictionary<string, List<object[]>>();
 
-         public static void Init()
 
-         {
 
-             GFGUIPackage.AddPackage(ResPathUtil.GetUIPackagePath("Common"));
 
-             UIConfig.buttonSound = (NAudioClip)UIPackage.GetItemAsset("Common", "click");
 
-             Font font0 = GFGAsset.Load<Font>(ResPathUtil.GetFontPath("FangZhengHeiTiJianTi-1", "ttf"));
 
-             FontManager.RegisterFont(new DynamicFont("FangZhengHeiTiJianTi-1", font0));
 
-             Font font1 = GFGAsset.Load<Font>(ResPathUtil.GetFontPath("FZKTJW--GB1-0", "ttf"));
 
-             FontManager.RegisterFont(new DynamicFont("FZKTJW--GB1-0", font1));
 
-             Font font2 = GFGAsset.Load<Font>(ResPathUtil.GetFontPath("SourceHanSerifCN-Regular-1", "otf"));
 
-             FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Regular-1", font2));
 
-             Font font3 = GFGAsset.Load<Font>(ResPathUtil.GetFontPath("SourceHanSerifCN-Bold-2", "otf"));
 
-             FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Bold-2", font3));
 
-             Font font4 = GFGAsset.Load<Font>(ResPathUtil.GetFontPath("SourceHanSerifCN-ExtraLight-3", "otf"));
 
-             FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-ExtraLight-3", font4));
 
-             Font font5 = GFGAsset.Load<Font>(ResPathUtil.GetFontPath("SourceHanSerifCN-Heavy-4", "otf"));
 
-             FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Heavy-4", font5));
 
-             Font font6 = GFGAsset.Load<Font>(ResPathUtil.GetFontPath("SourceHanSerifCN-Light-5", "otf"));
 
-             FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Light-5", font6));
 
-             Font font7 = GFGAsset.Load<Font>(ResPathUtil.GetFontPath("SourceHanSerifCN-Medium-6", "otf"));
 
-             FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-Medium-6", font7));
 
-             Font font8 = GFGAsset.Load<Font>(ResPathUtil.GetFontPath("SourceHanSerifCN-SemiBold-7", "otf"));
 
-             FontManager.RegisterFont(new DynamicFont("SourceHanSerifCN-SemiBold-7", font8));
 
-             UIConfig.defaultFont = "FZKTJW--GB1-0";
 
-             //默认关闭点击窗口移至顶层的功能,不可打开,如哪个界面需要在界面中单独设置
 
-             UIConfig.bringWindowToFrontOnClick = false;
 
-             _viewDic = new Dictionary<string, IUIView>();
 
-             //��ʼ����ͼ������
 
-             _bottomLayer = CreateLayer("BottomLayer");
 
-             _topLayer = CreateLayer("TopLayer");
 
-             _topLayer.sortingOrder = ConstSortingOrder.TOP;
 
-             _guideLayer = CreateLayer("GuideLayer");
 
-             _guideLayer.sortingOrder = ConstSortingOrder.Guide;
 
-             _modalLayer = CreateLayer("ModalLayer");
 
-             _modalLayer.sortingOrder = ConstSortingOrder.Modal;
 
-             _alertLayer = CreateLayer("AlertLayer");
 
-             _alertLayer.sortingOrder = ConstSortingOrder.Alert;
 
-             //debug层
 
-             _debugLayer = CreateLayer("DebugLayer");
 
-             _debugLayer.sortingOrder = ConstSortingOrder.Debug;
 
-             _floatLayer = CreateLayer("FloatLayer");
 
-             _floatLayer.sortingOrder = ConstSortingOrder.Float;
 
-             SetMaskAlpha(0.6f);
 
-         }
 
-         public static void AddChildToBottomLayer(GObject gObject)
 
-         {
 
-             _bottomLayer.AddChild(gObject);
 
-         }
 
-         public static void AddChildToTopLayer(GObject gObject)
 
-         {
 
-             _topLayer.AddChild(gObject);
 
-         }
 
-         public static void AddChildToGuideLayer(GObject gObject)
 
-         {
 
-             _guideLayer.AddChild(gObject);
 
-         }
 
-         public static void AddChildToModalLayer(GObject gObject)
 
-         {
 
-             _modalLayer.AddChild(gObject);
 
-         }
 
-         public static void AddChildToAlertLayer(GObject gObject)
 
-         {
 
-             _alertLayer.AddChild(gObject);
 
-         }
 
-         public static void AddChildToDebugLayer(GObject gObject)
 
-         {
 
-             _debugLayer.AddChild(gObject);
 
-         }
 
-         public static void AddChildToFloatLayer(GObject gObject)
 
-         {
 
-             _floatLayer.AddChild(gObject);
 
-         }
 
-         /// <summary>
 
-         /// ��ʾһ����ͼ
 
-         /// </summary>
 
-         /// <param name="name">Ҫ��ʾ����ͼ����</param>
 
-         /// <param name="viewData">Ҫ���ݸ���ͼ�IJ���</param>
 
-         /// <param name="goBackParams">�Ӹ���ͼ���ص���ͼ��Ϣ</param>
 
-         /// <param name="hideOthers">�Ƿ�ر�������ͼ</param>
 
-         public static bool Show(string fullViewName, object viewData = null, object[] goBackParams = null, bool hideOthers = false, bool resetGobackParams = false)
 
-         {
 
-             string name = GetName(fullViewName);
 
-             if (!GameGlobal.skipCheckOpen && !FunctionOpenDataManager.Instance.CheckIsFunOpenById(name))
 
-             {
 
-                 return false;
 
-             }
 
-             if (hideOthers)
 
-             {
 
-                 HideAllView(name);
 
-             }
 
-             IUIView obj = null;
 
-             if (_viewDic.ContainsKey(name))
 
-             {
 
-                 obj = _viewDic[name];
 
-             }
 
-             else
 
-             {
 
-                 obj = CreateViewInstance(fullViewName) as IUIView;
 
-                 obj.viewName = name;
 
-                 _viewDic.Add(name, obj);
 
-             }
 
-             if (obj != null)
 
-             {
 
-                 IUIView view = (IUIView)obj;
 
-                 view.viewData = viewData;
 
-                 if (!view.isShowing)
 
-                 {
 
-                     view.Show();
 
-                 }
 
-                 else
 
-                 {
 
-                     view.Refresh();
 
-                 }
 
-                 if (resetGobackParams)
 
-                 {
 
-                     if (_goBackDatas.ContainsKey(name) == true)
 
-                     {
 
-                         _goBackDatas.Remove(name);
 
-                     }
 
-                 }
 
-                 if (goBackParams != null)
 
-                 {
 
-                     if (!_goBackDatas.ContainsKey(name))
 
-                     {
 
-                         _goBackDatas.Add(name, new List<object[]>());
 
-                     }
 
-                     _goBackDatas[name].Add(goBackParams);
 
-                 }
 
-                 Debug.Log("当前打开:" + name);
 
-             }
 
-             return true;
 
-         }
 
-         public static bool isViewOpen(string fullViewName)
 
-         {
 
-             string name = GetName(fullViewName);
 
-             IUIView obj = null;
 
-             if (_viewDic.ContainsKey(name))
 
-             {
 
-                 obj = _viewDic[name];
 
-                 if (obj != null)
 
-                 {
 
-                     IUIView view = (IUIView)obj;
 
-                     if (view.isShowing) return true;
 
-                 }
 
-             }
 
-             return false;
 
-         }
 
-         public static bool Show<T>(object viewData = null, object[] goBackParams = null, bool hideOthers = false, bool resetGobackParams = false) where T : class, new()
 
-         {
 
-             // string[] names = typeof(T).FullName.Split('.');
 
-             // string viewName = names[names.Length - 1];
 
-             string name = GetName(typeof(T).FullName);
 
-             if (!GameGlobal.skipCheckOpen && !FunctionOpenDataManager.Instance.CheckIsFunOpenById(name))
 
-             {
 
-                 return false;
 
-             }
 
-             if (hideOthers)
 
-             {
 
-                 HideAllView(name);
 
-             }
 
-             IUIView obj = null;
 
-             if (_viewDic.ContainsKey(name))
 
-             {
 
-                 obj = _viewDic[name];
 
-             }
 
-             else
 
-             {
 
-                 obj = new T() as IUIView;
 
-                 obj.viewName = name;
 
-                 _viewDic.Add(name, obj);
 
-             }
 
-             if (obj != null)
 
-             {
 
-                 IUIView view = (IUIView)obj;
 
-                 view.viewData = viewData;
 
-                 if (!view.isShowing)
 
-                 {
 
-                     view.Show();
 
-                 }
 
-                 else
 
-                 {
 
-                     view.Refresh();
 
-                 }
 
-                 if (goBackParams != null)
 
-                 {
 
-                     if (!_goBackDatas.ContainsKey(name))
 
-                     {
 
-                         _goBackDatas.Add(name, new List<object[]>());
 
-                     }
 
-                     _goBackDatas[name].Add(goBackParams);
 
-                 }
 
-                 else if (resetGobackParams)
 
-                 {
 
-                     if (_goBackDatas.ContainsKey(name) == true)
 
-                     {
 
-                         _goBackDatas.Remove(name);
 
-                     }
 
-                 }
 
-                 Debug.Log("当前打开:" + name);
 
-             }
 
-             return true;
 
-         }
 
-         public static void Hide(string fullViewName)
 
-         {
 
-             string name = GetName(fullViewName);
 
-             if (!_viewDic.ContainsKey(name))
 
-             {
 
-                 return;
 
-             }
 
-             IUIView obj = _viewDic[name];
 
-             if (obj != null && obj.isShowing)
 
-             {
 
-                 IUIView view = (IUIView)obj;
 
-                 view.Hide();
 
-                 Debug.Log("当前关闭:" + name);
 
-             }
 
-         }
 
-         public static void Hide<T>()
 
-         {
 
-             string name = GetName(typeof(T).FullName);
 
-             if (!_viewDic.ContainsKey(name))
 
-             {
 
-                 return;
 
-             }
 
-             object obj = _viewDic[name];
 
-             if (obj != null)
 
-             {
 
-                 IUIView view = (IUIView)obj;
 
-                 view.Hide();
 
-                 Debug.Log("当前关闭:" + name);
 
-             }
 
-         }
 
-         public static void GoBackFrom(string fullViewName, bool hideOther = true)
 
-         {
 
-             string name = GetName(fullViewName);
 
-             ViewManager.Hide(name);
 
-             if (_goBackDatas.ContainsKey(name) && _goBackDatas[name].Count > 0)
 
-             {
 
-                 List<object[]> goBackdatas = _goBackDatas[name];
 
-                 object[] gobackItems = goBackdatas[goBackdatas.Count - 1];
 
-                 string tViewName = gobackItems[0] as string;
 
-                 object tViewData = null;
 
-                 if (gobackItems.Length > 1)
 
-                 {
 
-                     tViewData = gobackItems[1];
 
-                 }
 
-                 ViewManager.Show(tViewName, tViewData);
 
-                 _goBackDatas[name].RemoveAt(goBackdatas.Count - 1);
 
-             }
 
-             else
 
-             {
 
-                 MainDataManager.Instance.ViewType = 0;
 
-                 ViewManager.Show<MainUIView>(null, null, hideOther);
 
-             }
 
-         }
 
-         public static object[] GetGoBackDatas(string fullViewName)
 
-         {
 
-             string name = GetName(fullViewName);
 
-             object[] value = null;
 
-             if (_goBackDatas.ContainsKey(name) && _goBackDatas[name].Count > 0)
 
-             {
 
-                 value = _goBackDatas[name][_goBackDatas[name].Count - 1];
 
-             }
 
-             return value;
 
-         }
 
-         public static IUIView GetUIView(string viewName)
 
-         {
 
-             IUIView obj = _viewDic[viewName];
 
-             if (obj != null && obj.isShowing)
 
-             {
 
-                 return obj as IUIView;
 
-             }
 
-             return null;
 
-         }
 
-         public static void ClearUIView(string viewName)
 
-         {
 
-             if (!string.IsNullOrEmpty(viewName) && _viewDic.ContainsKey(viewName))
 
-             {
 
-                 if (_viewDic[viewName] != null && !_viewDic[viewName].isShowing)
 
-                 {
 
-                     // _viewDic[viewName] = null;
 
-                     _viewDic.Remove(viewName);
 
-                 }
 
-             }
 
-         }
 
-         public static void HideAllView(string excludeViewName = null)
 
-         {
 
-             for (int i = _viewDic.Keys.Count - 1; i >= 0; i--)//不用foreach是因为:循环过程中可能会触发dispose,导致_viewDic.Keys变化,最终报错
 
-             {
 
-                 int index = i > _viewDic.Keys.Count - 1 ? _viewDic.Keys.Count - 1 : i;//直接去最后一个,不用i是因为关闭一个界面可能会连带关闭其他界面,最终i比_viewDic.Keys.Count大而报错
 
-                 KeyValuePair<string, IUIView> kv = _viewDic.ElementAt(index);
 
-                 if (kv.Key != excludeViewName)
 
-                 {
 
-                     if (kv.Key == typeof(FunctionOpenView).Name) continue;//功能开启界面不能强制关闭
 
-                     Hide(kv.Key);
 
-                 }
 
-             }
 
-             // _viewDic.Clear();
 
-             // foreach (string viewName in _viewDic.Keys)
 
-             // {
 
-             //     if (viewName != excludeViewName)
 
-             //     {
 
-             //         if (viewName == typeof(FunctionOpenView).Name) continue;//功能开启界面不能强制关闭
 
-             //         Hide(viewName);
 
-             //     }
 
-             // }
 
-         }
 
-         public static void CheckDispsoe()
 
-         {
 
-             for (int i = _viewDic.Keys.Count - 1; i >= 0; i--)//不用foreach是因为:循环过程中可能会触发dispose,导致_viewDic.Keys变化,最终报错
 
-             {
 
-                 int index = i > _viewDic.Keys.Count - 1 ? _viewDic.Keys.Count - 1 : i;//直接去最后一个,不用i是因为关闭一个界面可能会连带关闭其他界面,最终i比_viewDic.Keys.Count大而报错
 
-                 KeyValuePair<string, IUIView> kv = _viewDic.ElementAt(index);
 
-                 if (kv.Value.isShowing == true) continue;
 
-                 // if (kv.Value.packageName == ResPathUtil.GetUIPackagePath("CommonGame") || kv.Value.packageName == ResPathUtil.GetUIPackagePath("Common") || kv.Value.packageName == ResPathUtil.GetUIPackagePath("Main")) return;//这几个包不释放
 
-                 long currentTime = TimeHelper.ClientNowSeconds();
 
-                 long closeTime = kv.Value.closeTime;
 
-                 if (closeTime > 0 && currentTime - closeTime >= TimeUtil.SECOND_PER_MUNITE * 1)
 
-                 {
 
-                     kv.Value.closeTime = 0;
 
-                     kv.Value.Dispose();
 
-                 }
 
-             }
 
-         }
 
-         private static object CreateViewInstance(string name)
 
-         {
 
-             // Debug.LogFormat("CreateViewInstance {0}", name);
 
-             Type type = Type.GetType(name);
 
-             if (type != null)
 
-             {
 
-                 return Activator.CreateInstance(type);
 
-             }
 
-             return null;
 
-         }
 
-         private static GComponent CreateLayer(string name)
 
-         {
 
-             GComponent layer = new GComponent();
 
-             layer.name = name;
 
-             GRoot.inst.AddChild(layer);
 
-             layer.SetSize(GRoot.inst.size.x, GRoot.inst.size.y);
 
-             layer.AddRelation(GRoot.inst, RelationType.Size);
 
-             return layer;
 
-         }
 
-         public static bool CheckIsTopView(GComponent viewCom)
 
-         {
 
-             if (ViewManager.isViewOpen(typeof(GuideView).Name)) return false;
 
-             if (viewCom.parent != null)
 
-             {
 
-                 int index = viewCom.parent.GetChildIndex(viewCom);
 
-                 if (index == viewCom.parent.numChildren - 1 && GRoot.inst.GetTopWindow() == null)
 
-                 {
 
-                     return true;
 
-                 }
 
-             }
 
-             if (GRoot.inst.GetTopWindow() == viewCom)
 
-             {
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         public static string GetName(string fullName)
 
-         {
 
-             string[] names = fullName.Split('.');
 
-             string name = names[names.Length - 1];
 
-             return name;
 
-         }
 
-         public static void SetMaskAlpha(float alpha)
 
-         {
 
-             GRoot.inst.modalLayer.alpha = alpha;
 
-         }
 
-         /// <summary>
 
-         /// 任务界面跳转
 
-         /// </summary>
 
-         /// <param name="jumpId"></param>
 
-         public static void JumpToView(string jumpId, object[] param, object[] goBackDatas, bool hideOther = true, Action onSuccess = null)
 
-         {
 
-             switch (jumpId)
 
-             {
 
-                 case nameof(LeagueAnswerView):
 
-                     if (LeagueDataManager.Instance.Type == LeagueJoinType.Join)
 
-                     {
 
-                         ViewManager.Show<LeagueView>(null, goBackDatas, hideOther);
 
-                         ViewManager.Show($"GFGGame.{jumpId}");
 
-                     }
 
-                     else
 
-                     {
 
-                         if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(nameof(LeagueView))) return;
 
-                         ViewManager.Show<LeagueJoinView>(null, goBackDatas, hideOther, true);
 
-                     }
 
-                     break;
 
-                 case nameof(LeagueView):
 
-                     if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(nameof(LeagueView))) return;
 
-                     if (LeagueDataManager.Instance.Type == LeagueJoinType.Join)
 
-                     {
 
-                         ViewManager.Show<LeagueView>(null, goBackDatas, hideOther);
 
-                     }
 
-                     else
 
-                     {
 
-                         ViewManager.Show<LeagueJoinView>(null, goBackDatas, hideOther, true);
 
-                     }
 
-                     break;
 
-                 case nameof(StoreView):
 
-                     ViewManager.Show<StoreView>(param, goBackDatas, hideOther);
 
-                     break;
 
-                 case nameof(StoryChapterListView):
 
-                     ViewManager.Show($"GFGGame.{jumpId}", param, goBackDatas, hideOther, true);
 
-                     break;
 
-                 case nameof(StoryChapterView):
 
-                     ViewManager.Show<StoryChapterView>(param[0], goBackDatas, hideOther);
 
-                     break;
 
-                 case nameof(FirstChargeBonusView):
 
-                     ViewManager.Show<FirstChargeBonusView>(param, goBackDatas, false);
 
-                     break;
 
-                 default:
 
-                     ViewManager.Show($"GFGGame.{jumpId}", null, goBackDatas, hideOther, true);
 
-                     break;
 
-             }
 
-             onSuccess?.Invoke();
 
-         }
 
-     }
 
- }
 
 
  |