ViewManager.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. using System.Collections.Generic;
  2. using System;
  3. using FairyGUI;
  4. using System.Linq;
  5. using ET;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class ViewStructure
  10. {
  11. public string name;
  12. public object viewData;
  13. public IUIView iUIView;
  14. public bool backRefresh;
  15. public List<String> smallWindow;
  16. }
  17. /// <summary>
  18. /// 视图管理类
  19. /// 管理视图的显示、隐藏
  20. /// </summary>
  21. public class ViewManager
  22. {
  23. private static List<ViewStructure> _viewStack;
  24. private static Dictionary<string, IUIView> _viewDic;
  25. private static GComponent _bottomLayer;
  26. private static GComponent _topLayer;
  27. private static GComponent _guideLayer;
  28. private static GComponent _modalLayer;
  29. private static GComponent _alertLayer;
  30. private static GComponent _debugLayer;
  31. private static GComponent _floatLayer;
  32. private static bool _nowHideOthers = false; //正在关闭所有界面的循环中
  33. private static Dictionary<string, List<object[]>> _goBackDatas = new Dictionary<string, List<object[]>>();
  34. public static void Clear()
  35. {
  36. _viewStack.Clear();
  37. }
  38. public static async void Init()
  39. {
  40. //设置CustomLoader
  41. UIObjectFactory.SetLoaderExtension(typeof(GFGGLoader));
  42. //通用资源,单独加,增加一次引用,不会被释放
  43. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Login"));
  44. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Common"));
  45. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("CommonGame"));
  46. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ActivityAfternoonTea"));
  47. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ActivityAFuGift"));
  48. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ActivityDay7"));
  49. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ActivityGetYuanXiao"));
  50. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ActivityHuaRongDao"));
  51. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ActivityMain"));
  52. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ActivityThemeLuckyBox"));
  53. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ActivityWanShiLi"));
  54. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Arena"));
  55. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Bag"));
  56. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("BlindBox"));
  57. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("BornLimit"));
  58. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Card"));
  59. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("CardSynthetic"));
  60. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ClothingDecompose"));
  61. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ClothingFoster"));
  62. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ClothingShop"));
  63. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ClothingSynthetic"));
  64. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("ClothingUpgrade"));
  65. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("CreateRole"));
  66. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("DailyWelfare"));
  67. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("DeleteAccount"));
  68. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("DressUp"));
  69. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("EnduringGiftBox"));
  70. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Field"));
  71. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("FieldGuide"));
  72. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("FieldWork"));
  73. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Friend"));
  74. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Guide"));
  75. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("InstanceZones"));
  76. // await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Launcher"));
  77. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("League"));
  78. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Loading"));
  79. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("LuckyBox"));
  80. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Mail"));
  81. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Main"));
  82. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("MatchingCompetition"));
  83. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("MiniGame"));
  84. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("NewYearLogin"));
  85. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("NewYearRedEnvelope"));
  86. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Notice"));
  87. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("OpenServerActivity"));
  88. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Poem"));
  89. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("PopWindow"));
  90. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("RoleInfo"));
  91. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("RoleLvUp"));
  92. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Share"));
  93. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Store"));
  94. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Studio"));
  95. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Task"));
  96. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("TimeTracing"));
  97. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Travel"));
  98. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("TurnTable"));
  99. await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("XiuFang"));
  100. //await GFGUIPackage.AddPackageAsync(ResPathUtil.GetUIPackagePath("Common"));
  101. UIConfig.buttonSound = (NAudioClip)UIPackage.GetItemAsset("Common", "click");
  102. //统一修改文字字体需要填写路径 ResIn/Font/FZKTJW--GB1-0
  103. UIConfig.defaultFont = "FZKTJW--GB1-0";
  104. //默认关闭点击窗口移至顶层的功能,不可打开,如哪个界面需要在界面中单独设置
  105. UIConfig.bringWindowToFrontOnClick = false;
  106. _viewDic = new Dictionary<string, IUIView>();
  107. _viewStack = new List<ViewStructure>();
  108. //初始化视图层容器
  109. _bottomLayer = CreateLayer("BottomLayer");
  110. //_bottomLayer.sortingOrder = ConstSortingOrder.Bottom;
  111. _topLayer = CreateLayer("TopLayer");
  112. _topLayer.sortingOrder = ConstViewLayerSortingOrder.TOP;
  113. _guideLayer = CreateLayer("GuideLayer");
  114. _guideLayer.sortingOrder = ConstViewLayerSortingOrder.Guide;
  115. _modalLayer = CreateLayer("ModalLayer");
  116. _modalLayer.sortingOrder = ConstViewLayerSortingOrder.Modal;
  117. _alertLayer = CreateLayer("AlertLayer");
  118. _alertLayer.sortingOrder = ConstViewLayerSortingOrder.Alert;
  119. //debug层
  120. _debugLayer = CreateLayer("DebugLayer");
  121. _debugLayer.sortingOrder = ConstViewLayerSortingOrder.Debug;
  122. _floatLayer = CreateLayer("FloatLayer");
  123. _floatLayer.sortingOrder = ConstViewLayerSortingOrder.Float;
  124. SetMaskAlpha(0.6f);
  125. }
  126. public static void AddChildToBottomLayer(GObject gObject)
  127. {
  128. _bottomLayer.AddChild(gObject);
  129. }
  130. public static void AddChildToTopLayer(GObject gObject)
  131. {
  132. _topLayer.AddChild(gObject);
  133. }
  134. public static void AddChildToGuideLayer(GObject gObject)
  135. {
  136. _guideLayer.AddChild(gObject);
  137. }
  138. public static void AddChildToModalLayer(GObject gObject)
  139. {
  140. _modalLayer.AddChild(gObject);
  141. }
  142. public static void AddChildToAlertLayer(GObject gObject)
  143. {
  144. _alertLayer.AddChild(gObject);
  145. }
  146. public static void AddChildToDebugLayer(GObject gObject)
  147. {
  148. _debugLayer.AddChild(gObject);
  149. }
  150. public static void AddChildToFloatLayer(GObject gObject)
  151. {
  152. _floatLayer.AddChild(gObject);
  153. }
  154. public static float ViewWidth
  155. {
  156. get
  157. {
  158. //这里做了最大宽度适配
  159. float maxAspectRatio = 1080 * 1.0f / 1920;
  160. if (Screen.width * 1.0f / Screen.height > maxAspectRatio)
  161. {
  162. return GRoot.inst.height * maxAspectRatio;
  163. }
  164. return GRoot.inst.width;
  165. }
  166. }
  167. /// <summary>
  168. /// 显示一个视图
  169. /// </summary>
  170. /// <param name="viewName">要显示的视图名称</param>
  171. /// <param name="viewData">要传递给视图的参数</param>
  172. /// <param name="goBackParams">从该视图返回的视图信息</param>
  173. /// <param name="hideOthers">是否关闭其他视图</param>
  174. /// <param name="backRefresh">返回上一个界面的时候,上一个界面是否需要刷新界面</param>
  175. public static bool Show(string fullViewName, object viewData = null, bool hideOthers = false,
  176. bool backRefresh = true, bool isHideToShow = false)
  177. {
  178. string name = GetName(fullViewName);
  179. if (!GameGlobal.skipCheckOpen && !FunctionOpenDataManager.Instance.CheckIsFunOpenById(name))
  180. {
  181. return false;
  182. }
  183. if (hideOthers)
  184. {
  185. HideAllView(name);
  186. }
  187. IUIView obj = null;
  188. if (_viewDic.ContainsKey(name))
  189. {
  190. obj = _viewDic[name];
  191. }
  192. else
  193. {
  194. obj = CreateViewInstance(fullViewName) as IUIView;
  195. obj.viewName = name;
  196. _viewDic.Add(name, obj);
  197. }
  198. if (obj != null)
  199. {
  200. IUIView view = (IUIView)obj;
  201. view.viewData = viewData;
  202. if (!view.isShowing)
  203. {
  204. if (isHideToShow && _viewStack.Count > 0)
  205. {
  206. view.backRefresh = _viewStack[_viewStack.Count - 1].backRefresh;
  207. _viewStack[_viewStack.Count - 1].iUIView = obj;
  208. }
  209. else
  210. view.backRefresh = true;
  211. view.Show();
  212. }
  213. else
  214. {
  215. view.Refresh();
  216. }
  217. LogUtil.LogDev("当前打开:" + name);
  218. }
  219. if (name == "MainUIView")
  220. {
  221. _viewStack.Clear();
  222. }
  223. //判断是否需要保存界面数据, 会帮助关闭上一个保存界面
  224. if (obj.isReturnView && (_viewStack.Count <= 0 ||
  225. (_viewStack.Count > 0 && _viewStack[_viewStack.Count - 1].name != name)))
  226. {
  227. //保存上一个界面是否需要返回刷新
  228. if (!isHideToShow && _viewStack.Count > 1)
  229. _viewStack[_viewStack.Count - 1].backRefresh = backRefresh;
  230. ViewStructure viewStructure = new ViewStructure();
  231. viewStructure.name = name;
  232. viewStructure.viewData = viewData;
  233. viewStructure.iUIView = obj;
  234. _viewStack.Add(viewStructure);
  235. if (_viewStack.Count > 1 && !hideOthers)
  236. {
  237. if (_viewStack[_viewStack.Count - 2].smallWindow == null)
  238. _viewStack[_viewStack.Count - 2].smallWindow = new List<string>();
  239. _viewStack[_viewStack.Count - 2].smallWindow.Clear();
  240. //把开着的小弹窗存起来
  241. foreach (var objName in _viewDic.Keys)
  242. {
  243. IUIView view = (IUIView)_viewDic[objName];
  244. if (view.isReturnWindow)
  245. {
  246. if (view.isShowing)
  247. {
  248. _viewStack[_viewStack.Count - 2].smallWindow.Add(objName);
  249. view.Hide();
  250. }
  251. }
  252. }
  253. _viewStack[_viewStack.Count - 2].iUIView.Hide();
  254. }
  255. }
  256. return true;
  257. }
  258. //
  259. /// <summary>
  260. /// 界面可返回栈里的跳转
  261. /// </summary>
  262. /// <param name="viewName">跳转到界面缓存栈里的某个界面,使用这个参数时写在打开下一个界面后</param>
  263. /// <param name="count">删除队列中的倒数几个,较灵活应对更多种情况,可自由控制</param>
  264. public static void DeleteViewStackCountDown(string viewName, int count = 0)
  265. {
  266. if (viewName != null && viewName != "")
  267. {
  268. for (int i = _viewStack.Count - 2; i > 0; i--)
  269. {
  270. ViewStructure viewStructure = _viewStack[i];
  271. if (viewStructure.name == viewName)
  272. break;
  273. _viewStack.RemoveAt(i);
  274. }
  275. return;
  276. }
  277. for (int i = 0; i < count; i++)
  278. {
  279. if (_viewStack.Count <= 1)
  280. break;
  281. _viewStack.RemoveAt(_viewStack.Count - 1);
  282. }
  283. }
  284. public static bool isViewOpen(string fullViewName)
  285. {
  286. string name = GetName(fullViewName);
  287. IUIView obj = null;
  288. if (_viewDic.ContainsKey(name))
  289. {
  290. obj = _viewDic[name];
  291. if (obj != null)
  292. {
  293. IUIView view = (IUIView)obj;
  294. if (view.isShowing) return true;
  295. }
  296. }
  297. return false;
  298. }
  299. public static bool Show<T>(object viewData = null, bool hideOthers = false, bool backRefresh = true)
  300. where T : class, new()
  301. {
  302. // string[] names = typeof(T).FullName.Split('.');
  303. // string viewName = names[names.Length - 1];
  304. //string name = GetName(typeof(T).FullName);
  305. return ViewManager.Show(typeof(T).FullName, viewData, hideOthers, backRefresh);
  306. }
  307. public static void HideWin(string viewName)
  308. {
  309. if (_nowHideOthers)
  310. return;
  311. if (_viewStack.Count >= 1)
  312. {
  313. bool hasShowingView = false;
  314. bool needShowNextView = false;
  315. bool backRefresh = true;
  316. foreach (var info in _viewDic.Keys)
  317. {
  318. IUIView objIsShowing = _viewDic[info];
  319. if (objIsShowing != null && objIsShowing.isShowing)
  320. {
  321. hasShowingView = true;
  322. break;
  323. }
  324. }
  325. ViewStructure viewStructure = _viewStack[_viewStack.Count - 1];
  326. if (_viewStack.Count == 1)
  327. {
  328. //没有界面显示了,栈被清除剩1个的时候,做保底
  329. if (!hasShowingView)
  330. needShowNextView = true;
  331. }
  332. else
  333. {
  334. if (!hasShowingView || (viewStructure.iUIView.isReturnView && viewStructure.name == viewName))
  335. {
  336. //关闭自己,在队列里去除
  337. if (viewStructure.iUIView.isReturnView && viewStructure.name == viewName)
  338. {
  339. backRefresh = viewStructure.backRefresh;
  340. _viewStack.RemoveAt(_viewStack.Count - 1);
  341. }
  342. if (_viewStack.Count >= 1)
  343. needShowNextView = true;
  344. }
  345. }
  346. if (needShowNextView)
  347. {
  348. viewStructure = _viewStack[_viewStack.Count - 1];
  349. ViewManager.Show($"GFGGame.{viewStructure.name}", viewStructure.viewData, false, backRefresh, true);
  350. //重新打开小弹窗
  351. if (viewStructure.smallWindow != null)
  352. {
  353. foreach (var objName in viewStructure.smallWindow)
  354. {
  355. ViewManager.Show($"GFGGame.{objName}");
  356. }
  357. }
  358. //foreach (var objName in _viewDic.Keys)
  359. //{
  360. // if (objName != viewStructure.name)
  361. // {
  362. // IUIView view = (IUIView)_viewDic[objName];
  363. // if (view.isShowing)
  364. // view.Show();
  365. // }
  366. //}
  367. }
  368. }
  369. }
  370. public static void Hide(string fullViewName)
  371. {
  372. string name = GetName(fullViewName);
  373. if (!_viewDic.ContainsKey(name))
  374. {
  375. return;
  376. }
  377. object obj = _viewDic[name];
  378. if (obj != null)
  379. {
  380. IUIView view = (IUIView)obj;
  381. view.Hide();
  382. LogUtil.LogDev("当前关闭:" + name);
  383. }
  384. }
  385. public static void Hide<T>()
  386. {
  387. //string name = GetName(typeof(T).FullName);
  388. Hide(typeof(T).FullName);
  389. }
  390. public static void GoBackFrom(string fullViewName, bool hideOther = true)
  391. {
  392. string name = GetName(fullViewName);
  393. ViewManager.Hide(name);
  394. foreach (var info in _viewDic.Keys)
  395. {
  396. IUIView objIsShowing = _viewDic[info];
  397. if (objIsShowing != null && objIsShowing.isShowing)
  398. {
  399. return;
  400. }
  401. }
  402. MainDataManager.Instance.ViewType = 0;
  403. ViewManager.Show<MainUIView>(null, true);
  404. }
  405. public static object[] GetGoBackDatas(string fullViewName)
  406. {
  407. //string name = GetName(fullViewName);
  408. object[] value = null;
  409. //if (_goBackDatas.ContainsKey(name) && _goBackDatas[name].Count > 0)
  410. //{
  411. // value = _goBackDatas[name][_goBackDatas[name].Count - 1];
  412. //}
  413. return value;
  414. }
  415. public static IUIView GetUIView(string viewName)
  416. {
  417. if (_viewDic.ContainsKey(viewName))
  418. {
  419. IUIView obj = _viewDic[viewName];
  420. if (obj != null && obj.isShowing)
  421. {
  422. return obj as IUIView;
  423. }
  424. }
  425. return null;
  426. }
  427. public static void ClearUIView(string viewName)
  428. {
  429. if (!string.IsNullOrEmpty(viewName) && _viewDic.ContainsKey(viewName))
  430. {
  431. if (_viewDic[viewName] != null && !_viewDic[viewName].isShowing)
  432. {
  433. // _viewDic[viewName] = null;
  434. _viewDic.Remove(viewName);
  435. }
  436. }
  437. }
  438. public static void HideAllView(string excludeViewName = null)
  439. {
  440. for (int i = _viewDic.Keys.Count - 1; i >= 0; i--) //不用foreach是因为:循环过程中可能会触发dispose,导致_viewDic.Keys变化,最终报错
  441. {
  442. int index = i > _viewDic.Keys.Count - 1
  443. ? _viewDic.Keys.Count - 1
  444. : i; //直接去最后一个,不用i是因为关闭一个界面可能会连带关闭其他界面,最终i比_viewDic.Keys.Count大而报错
  445. KeyValuePair<string, IUIView> kv = _viewDic.ElementAt(index);
  446. if (kv.Key != excludeViewName)
  447. {
  448. if (kv.Key == typeof(FunctionOpenView).Name) continue; //功能开启界面不能强制关闭
  449. _nowHideOthers = true;
  450. Hide(kv.Key);
  451. }
  452. }
  453. _nowHideOthers = false;
  454. // _viewDic.Clear();
  455. // foreach (string viewName in _viewDic.Keys)
  456. // {
  457. // if (viewName != excludeViewName)
  458. // {
  459. // if (viewName == typeof(FunctionOpenView).Name) continue;//功能开启界面不能强制关闭
  460. // Hide(viewName);
  461. // }
  462. // }
  463. }
  464. public static void CheckDispose()
  465. {
  466. for (int i = _viewDic.Keys.Count - 1; i >= 0; i--) //不用foreach是因为:循环过程中可能会触发dispose,导致_viewDic.Keys变化,最终报错
  467. {
  468. int index = i > _viewDic.Keys.Count - 1
  469. ? _viewDic.Keys.Count - 1
  470. : i; //直接去最后一个,不用i是因为关闭一个界面可能会连带关闭其他界面,最终i比_viewDic.Keys.Count大而报错
  471. KeyValuePair<string, IUIView> kv = _viewDic.ElementAt(index);
  472. if (kv.Value.isShowing == true) continue;
  473. // if (kv.Value.packageName == ResPathUtil.GetUIPackagePath("CommonGame") || kv.Value.packageName == ResPathUtil.GetUIPackagePath("Common") || kv.Value.packageName == ResPathUtil.GetUIPackagePath("Main")) return;//这几个包不释放
  474. if (_viewDic.Keys.Count <= 10) return; //打开界面小于10个就不销毁了
  475. long currentTime = TimeHelper.ClientNowSeconds();
  476. long closeTime = kv.Value.closeTime;
  477. if (closeTime > 0 && currentTime - closeTime >= TimeUtil.SECOND_PER_MUNITE * 1)
  478. {
  479. kv.Value.closeTime = 0;
  480. kv.Value.Dispose();
  481. }
  482. }
  483. }
  484. private static object CreateViewInstance(string name)
  485. {
  486. //LogUtil.LogFormatDev("CreateViewInstance {0}", name);
  487. Type type = Type.GetType(name);
  488. if (type != null)
  489. {
  490. return Activator.CreateInstance(type);
  491. }
  492. return null;
  493. }
  494. private static GComponent CreateLayer(string name)
  495. {
  496. GComponent layer = new GComponent();
  497. layer.name = name;
  498. GRoot.inst.AddChild(layer);
  499. layer.SetSize(GRoot.inst.size.x, GRoot.inst.size.y);
  500. layer.AddRelation(GRoot.inst, RelationType.Size);
  501. return layer;
  502. }
  503. public static bool CheckIsTopView(GComponent viewCom)
  504. {
  505. if (ViewManager.isViewOpen(typeof(GuideView).Name)) return false;
  506. if (viewCom.parent != null)
  507. {
  508. int index = viewCom.parent.GetChildIndex(viewCom);
  509. if (index == viewCom.parent.numChildren - 1 && GRoot.inst.GetTopWindow() == null)
  510. {
  511. return true;
  512. }
  513. }
  514. if (GRoot.inst.GetTopWindow() == viewCom)
  515. {
  516. return true;
  517. }
  518. return false;
  519. }
  520. public static string GetName(string fullName)
  521. {
  522. string[] names = fullName.Split('.');
  523. string name = names[names.Length - 1];
  524. return name;
  525. }
  526. public static void SetMaskAlpha(float alpha)
  527. {
  528. GRoot.inst.modalLayer.alpha = alpha;
  529. }
  530. /// <summary>
  531. /// 任务界面跳转
  532. /// </summary>
  533. /// <param name="jumpId"></param>
  534. public static void JumpToView(string jumpId, object[] param, bool hideOther = false, bool backRefresh = true,
  535. Action onSuccess = null)
  536. {
  537. switch (jumpId)
  538. {
  539. case nameof(LeagueAnswerView):
  540. if (LeagueDataManager.Instance.Type == LeagueJoinType.Join)
  541. {
  542. ViewManager.Show<LeagueView>(null, hideOther, backRefresh);
  543. ViewManager.Show($"GFGGame.{jumpId}");
  544. }
  545. else
  546. {
  547. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(nameof(LeagueView))) return;
  548. ViewManager.Show<LeagueJoinView>(null, hideOther, backRefresh);
  549. }
  550. break;
  551. case nameof(LeagueView):
  552. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(nameof(LeagueView))) return;
  553. if (LeagueDataManager.Instance.Type == LeagueJoinType.Join)
  554. {
  555. ViewManager.Show<LeagueView>(null, hideOther, backRefresh);
  556. }
  557. else
  558. {
  559. ViewManager.Show<LeagueJoinView>(null, hideOther, backRefresh);
  560. }
  561. break;
  562. case nameof(StoreView):
  563. ViewManager.Show<StoreView>(param, hideOther, backRefresh);
  564. break;
  565. case nameof(StoryChapterListView):
  566. ViewManager.Show($"GFGGame.{jumpId}", param, hideOther, backRefresh);
  567. break;
  568. case nameof(StoryChapterView):
  569. ViewManager.Show<StoryChapterView>(param[0], hideOther, backRefresh);
  570. break;
  571. case nameof(FirstChargeBonusView):
  572. ViewManager.Show<FirstChargeBonusView>(param, false, backRefresh);
  573. break;
  574. case nameof(ClothingSyntheticView):
  575. ViewManager.Show<ClothingSyntheticView>(param, hideOther, backRefresh);
  576. break;
  577. case nameof(LuckyBoxView):
  578. if (param.Length > 0)
  579. ViewManager.Show<LuckyBoxView>(param[0], hideOther, backRefresh);
  580. else
  581. ViewManager.Show<LuckyBoxView>(null, hideOther, backRefresh);
  582. break;
  583. default:
  584. ViewManager.Show($"GFGGame.{jumpId}", null, hideOther, backRefresh);
  585. break;
  586. }
  587. onSuccess?.Invoke();
  588. }
  589. }
  590. }