UIManager.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. using System.Text.RegularExpressions;
  6. using UnityEngine.EventSystems;
  7. [RequireComponent(typeof(UIStackManager))]
  8. [RequireComponent(typeof(UILayerManager))]
  9. [RequireComponent(typeof(UIAnimManager))]
  10. public class UIManager : MonoBehaviour
  11. {
  12. private static GameObject s_UIManagerGo;
  13. private static UILayerManager s_UILayerManager; //UI层级管理器
  14. private static UIAnimManager s_UIAnimManager; //UI动画管理器
  15. private static UIStackManager s_UIStackManager; //UI栈管理器
  16. //public static Camera s_UIcamera; //UICamera
  17. private static EventSystem s_EventSystem;
  18. static public Dictionary<string, List<UIWindowBase>> s_UIs = new Dictionary<string, List<UIWindowBase>>(); //打开的UI
  19. static public Dictionary<string, List<UIWindowBase>> s_hideUIs = new Dictionary<string, List<UIWindowBase>>(); //隐藏的UI
  20. #region 初始化
  21. static bool isInit;
  22. public static void Init()
  23. {
  24. if(!isInit)
  25. {
  26. isInit = true;
  27. GameObject instance = GameObject.Find("UIManager");
  28. if (instance == null)
  29. {
  30. instance = GameObjectManager.CreateGameObjectByPool("UIManager");
  31. }
  32. UIManagerGo = instance;
  33. s_UILayerManager = instance.GetComponent<UILayerManager>();
  34. s_UIAnimManager = instance.GetComponent<UIAnimManager>();
  35. s_UIStackManager = instance.GetComponent<UIStackManager>();
  36. s_EventSystem = instance.GetComponentInChildren<EventSystem>();
  37. if (Application.isPlaying)
  38. {
  39. DontDestroyOnLoad(instance);
  40. }
  41. }
  42. }
  43. ///异步加载UIMnager
  44. //public static void InitAsync()
  45. //{
  46. // GameObject instance = GameObject.Find("UIManager");
  47. // if (instance == null)
  48. // {
  49. // GameObjectManager.CreateGameObjectByPoolAsync("UIManager",(obj)=> {
  50. // SetUIManager(obj);
  51. // });
  52. // }
  53. // else
  54. // {
  55. // SetUIManager(instance);
  56. // }
  57. //}
  58. static void SetUIManager(GameObject instance)
  59. {
  60. UIManagerGo = instance;
  61. UILayerManager = instance.GetComponent<UILayerManager>();
  62. UIAnimManager = instance.GetComponent<UIAnimManager>();
  63. DontDestroyOnLoad(instance);
  64. }
  65. public static UILayerManager UILayerManager
  66. {
  67. get
  68. {
  69. if (s_UILayerManager == null)
  70. {
  71. Init();
  72. }
  73. return s_UILayerManager;
  74. }
  75. set
  76. {
  77. s_UILayerManager = value;
  78. }
  79. }
  80. public static UIAnimManager UIAnimManager
  81. {
  82. get
  83. {
  84. if (s_UILayerManager == null)
  85. {
  86. Init();
  87. }
  88. return s_UIAnimManager;
  89. }
  90. set
  91. {
  92. s_UIAnimManager = value;
  93. }
  94. }
  95. public static UIStackManager UIStackManager
  96. {
  97. get
  98. {
  99. if (s_UIStackManager == null)
  100. {
  101. Init();
  102. }
  103. return s_UIStackManager;
  104. }
  105. set
  106. {
  107. s_UIStackManager = value;
  108. }
  109. }
  110. public static EventSystem EventSystem
  111. {
  112. get
  113. {
  114. if (s_EventSystem == null)
  115. {
  116. Init();
  117. }
  118. return s_EventSystem;
  119. }
  120. set
  121. {
  122. s_EventSystem = value;
  123. }
  124. }
  125. public static GameObject UIManagerGo
  126. {
  127. get
  128. {
  129. if (s_UIManagerGo == null)
  130. {
  131. Init();
  132. }
  133. return s_UIManagerGo;
  134. }
  135. set
  136. {
  137. s_UIManagerGo = value;
  138. }
  139. }
  140. #endregion
  141. #region EventSystem
  142. public static void SetEventSystemEnable(bool enable)
  143. {
  144. if(EventSystem != null)
  145. {
  146. EventSystem.enabled = enable;
  147. }
  148. else
  149. {
  150. Debug.LogError("EventSystem.current is null !");
  151. }
  152. }
  153. #endregion
  154. #region UICamera
  155. public static string[] GetCameraNames()
  156. {
  157. string[] list = new string[UILayerManager.UICameraList.Count];
  158. for (int i = 0; i < UILayerManager.UICameraList.Count; i++)
  159. {
  160. list[i] = UILayerManager.UICameraList[i].m_key;
  161. }
  162. return list;
  163. }
  164. public static Camera GetCamera(string CameraKey = null)
  165. {
  166. var data = UILayerManager.GetUICameraDataByKey(CameraKey);
  167. return data.m_camera;
  168. }
  169. /// <summary>
  170. /// 将一个UI移动到另一个UICamera下
  171. /// </summary>
  172. /// <param name="ui"></param>
  173. /// <param name="cameraKey"></param>
  174. public static void ChangeUICamera(UIWindowBase ui, string cameraKey)
  175. {
  176. UILayerManager.SetLayer(ui, cameraKey);
  177. }
  178. /// <summary>
  179. /// 将一个UI重新放回它原本的UICamera下
  180. /// </summary>
  181. /// <param name="ui"></param>
  182. /// <param name="cameraKey"></param>
  183. public static void ResetUICamera(UIWindowBase ui)
  184. {
  185. UILayerManager.SetLayer(ui, ui.cameraKey);
  186. }
  187. #endregion
  188. #region UI的打开与关闭方法
  189. /// <summary>
  190. /// 创建UI,如果不打开则存放在Hide列表中
  191. /// </summary>
  192. /// <typeparam name="T"></typeparam>
  193. /// <returns></returns>
  194. public static T CreateUIWindow<T>() where T : UIWindowBase
  195. {
  196. return (T)CreateUIWindow(typeof(T).Name);
  197. }
  198. public static UIWindowBase CreateUIWindow(string UIName)
  199. {
  200. GameObject UItmp = GameObjectManager.CreateGameObjectByPool(UIName, UIManagerGo);
  201. UIWindowBase UIWIndowBase = UItmp.GetComponent<UIWindowBase>();
  202. UISystemEvent.Dispatch(UIWIndowBase, UIEvent.OnInit); //派发OnInit事件
  203. UIWIndowBase.windowStatus = UIWindowBase.WindowStatus.Create;
  204. try
  205. {
  206. UIWIndowBase.InitWindow(GetUIID(UIName));
  207. }
  208. catch(Exception e)
  209. {
  210. Debug.LogError(UIName + "OnInit Exception: " + e.ToString());}
  211. AddHideUI(UIWIndowBase);
  212. UILayerManager.SetLayer(UIWIndowBase); //设置层级
  213. return UIWIndowBase;
  214. }
  215. /// <summary>
  216. /// 打开UI
  217. /// </summary>
  218. /// <param name="UIName">UI名</param>
  219. /// <param name="callback">动画播放完毕回调</param>
  220. /// <param name="objs">回调传参</param>`
  221. /// <returns>返回打开的UI</returns>
  222. public static UIWindowBase OpenUIWindow(string UIName, UICallBack callback = null, params object[] objs)
  223. {
  224. UIWindowBase UIbase = GetHideUI(UIName);
  225. if (UIbase == null)
  226. {
  227. UIbase = CreateUIWindow(UIName);
  228. }
  229. RemoveHideUI(UIbase);
  230. AddUI(UIbase);
  231. UIStackManager.OnUIOpen(UIbase);
  232. UILayerManager.SetLayer(UIbase); //设置层级
  233. UIbase.windowStatus = UIWindowBase.WindowStatus.OpenAnim;
  234. UISystemEvent.Dispatch(UIbase, UIEvent.OnOpen); //派发OnOpen事件
  235. try
  236. {
  237. UIbase.OnOpen();
  238. }
  239. catch (Exception e)
  240. {
  241. Debug.LogError(UIName + " OnOpen Exception: " + e.ToString());
  242. }
  243. UISystemEvent.Dispatch(UIbase, UIEvent.OnOpened); //派发OnOpened事件
  244. UIAnimManager.StartEnterAnim(UIbase, callback, objs); //播放动画
  245. return UIbase;
  246. }
  247. public static T OpenUIWindow<T>() where T : UIWindowBase
  248. {
  249. return (T)OpenUIWindow(typeof(T).Name);
  250. }
  251. /// <summary>
  252. /// 关闭UI
  253. /// </summary>
  254. /// <param name="UI">目标UI</param>
  255. /// <param name="isPlayAnim">是否播放关闭动画</param>
  256. /// <param name="callback">动画播放完毕回调</param>
  257. /// <param name="objs">回调传参</param>
  258. public static void CloseUIWindow(UIWindowBase UI,bool isPlayAnim = true ,UICallBack callback = null, params object[] objs)
  259. {
  260. RemoveUI(UI); //移除UI引用
  261. UI.RemoveAllListener();
  262. //s_UILayerManager.RemoveUI(UI);
  263. if (isPlayAnim)
  264. {
  265. //动画播放完毕删除UI
  266. if (callback != null)
  267. {
  268. callback += CloseUIWindowCallBack;
  269. }
  270. else
  271. {
  272. callback = CloseUIWindowCallBack;
  273. }
  274. UI.windowStatus = UIWindowBase.WindowStatus.CloseAnim;
  275. UIAnimManager.StartExitAnim(UI, callback, objs);
  276. }
  277. else
  278. {
  279. CloseUIWindowCallBack(UI, objs);
  280. }
  281. }
  282. static void CloseUIWindowCallBack(UIWindowBase UI, params object[] objs)
  283. {
  284. UI.windowStatus = UIWindowBase.WindowStatus.Close;
  285. UISystemEvent.Dispatch(UI, UIEvent.OnClose); //派发OnClose事件
  286. try
  287. {
  288. UI.OnClose();
  289. }
  290. catch (Exception e)
  291. {
  292. Debug.LogError(UI.UIName + " OnClose Exception: " + e.ToString());
  293. }
  294. UIStackManager.OnUIClose(UI);
  295. AddHideUI(UI);
  296. UISystemEvent.Dispatch(UI, UIEvent.OnClosed); //派发OnOpened事件
  297. }
  298. public static void CloseUIWindow(string UIname, bool isPlayAnim = true, UICallBack callback = null, params object[] objs)
  299. {
  300. UIWindowBase ui = GetUI(UIname);
  301. if (ui == null)
  302. {
  303. Debug.LogError("CloseUIWindow Error UI ->" + UIname + "<- not Exist!");
  304. }
  305. else
  306. {
  307. CloseUIWindow(GetUI(UIname), isPlayAnim, callback, objs);
  308. }
  309. }
  310. public static void CloseUIWindow<T>(bool isPlayAnim = true, UICallBack callback = null, params object[] objs) where T : UIWindowBase
  311. {
  312. CloseUIWindow(typeof(T).Name, isPlayAnim,callback, objs);
  313. }
  314. public static UIWindowBase ShowUI(string UIname)
  315. {
  316. UIWindowBase ui = GetUI(UIname);
  317. return ShowUI(ui);
  318. }
  319. public static UIWindowBase ShowUI(UIWindowBase ui)
  320. {
  321. ui.windowStatus = UIWindowBase.WindowStatus.Open;
  322. UISystemEvent.Dispatch(ui, UIEvent.OnShow); //派发OnShow事件
  323. try
  324. {
  325. ui.Show();
  326. ui.OnShow();
  327. }
  328. catch (Exception e)
  329. {
  330. Debug.LogError(ui.UIName + " OnShow Exception: " + e.ToString());
  331. }
  332. return ui;
  333. }
  334. public static UIWindowBase HideUI(string UIname)
  335. {
  336. UIWindowBase ui = GetUI(UIname);
  337. return HideUI(ui);
  338. }
  339. public static UIWindowBase HideUI(UIWindowBase ui)
  340. {
  341. ui.windowStatus = UIWindowBase.WindowStatus.Hide;
  342. UISystemEvent.Dispatch(ui, UIEvent.OnHide); //派发OnHide事件
  343. try
  344. {
  345. ui.Hide();
  346. ui.OnHide();
  347. }
  348. catch (Exception e)
  349. {
  350. Debug.LogError(ui.UIName + " OnShow Exception: " + e.ToString());
  351. }
  352. return ui;
  353. }
  354. public static void HideOtherUI(string UIName)
  355. {
  356. List<string> keys = new List<string>(s_UIs.Keys);
  357. for (int i = 0; i < keys.Count; i++)
  358. {
  359. List<UIWindowBase> list = s_UIs[keys[i]];
  360. for (int j = 0; j < list.Count; j++)
  361. {
  362. if (list[j].UIName != UIName)
  363. {
  364. HideUI(list[j]);
  365. }
  366. }
  367. }
  368. }
  369. public static void ShowOtherUI(string UIName)
  370. {
  371. List<string> keys = new List<string>(s_UIs.Keys);
  372. for (int i = 0; i < keys.Count; i++)
  373. {
  374. List<UIWindowBase> list = s_UIs[keys[i]];
  375. for (int j = 0; j < list.Count; j++)
  376. {
  377. if (list[j].UIName != UIName)
  378. {
  379. ShowUI(list[j]);
  380. }
  381. }
  382. }
  383. }
  384. /// <summary>
  385. /// 移除全部UI
  386. /// </summary>
  387. public static void CloseAllUI(bool isPlayerAnim = false)
  388. {
  389. List<string> keys = new List<string>(s_UIs.Keys);
  390. for (int i = 0; i < keys.Count; i++)
  391. {
  392. List<UIWindowBase> list = s_UIs[keys[i]];
  393. for(int j = 0;j<list.Count;j++)
  394. {
  395. CloseUIWindow(list[i], isPlayerAnim);
  396. }
  397. }
  398. }
  399. public static void CloseLastUI(UIType uiType = UIType.Normal)
  400. {
  401. UIStackManager.CloseLastUIWindow(uiType);
  402. }
  403. #endregion
  404. #region UI的打开与关闭 异步方法
  405. public static void OpenUIAsync<T>( UICallBack callback, params object[] objs) where T : UIWindowBase
  406. {
  407. string UIName = typeof(T).Name;
  408. OpenUIAsync(UIName,callback,objs);
  409. }
  410. public static void OpenUIAsync(string UIName , UICallBack callback, params object[] objs)
  411. {
  412. ResourceManager.LoadAsync(UIName, (loadState,resObject) =>
  413. {
  414. if(loadState.isDone)
  415. {
  416. OpenUIWindow(UIName, callback, objs);
  417. }
  418. });
  419. }
  420. #endregion
  421. #region UI内存管理
  422. public static void DestroyUI(UIWindowBase UI)
  423. {
  424. Debug.Log("UIManager DestroyUI " + UI.name);
  425. if (GetIsExitsHide(UI))
  426. {
  427. RemoveHideUI(UI);
  428. }
  429. else if(GetIsExits(UI))
  430. {
  431. RemoveUI(UI);
  432. }
  433. UISystemEvent.Dispatch(UI, UIEvent.OnDestroy); //派发OnDestroy事件
  434. try
  435. {
  436. UI.Dispose();
  437. }
  438. catch(Exception e)
  439. {
  440. Debug.LogError("OnDestroy :" + e.ToString());
  441. }
  442. GameObjectManager.DestroyGameObjectByPool(UI.gameObject);
  443. }
  444. public static void DestroyAllUI()
  445. {
  446. DestroyAllActiveUI();
  447. DestroyAllHideUI();
  448. }
  449. #endregion
  450. #region 打开UI列表的管理
  451. /// <summary>
  452. /// 删除所有打开的UI
  453. /// </summary>
  454. public static void DestroyAllActiveUI()
  455. {
  456. foreach (List<UIWindowBase> uis in s_UIs.Values)
  457. {
  458. for (int i = 0; i < uis.Count; i++)
  459. {
  460. UISystemEvent.Dispatch(uis[i], UIEvent.OnDestroy); //派发OnDestroy事件
  461. try
  462. {
  463. uis[i].Dispose();
  464. }
  465. catch (Exception e)
  466. {
  467. Debug.LogError("OnDestroy :" + e.ToString());
  468. }
  469. GameObjectManager.DestroyGameObjectByPool(uis[i].gameObject);
  470. }
  471. }
  472. s_UIs.Clear();
  473. }
  474. public static T GetUI<T>() where T : UIWindowBase
  475. {
  476. return (T)GetUI(typeof(T).Name);
  477. }
  478. public static UIWindowBase GetUI(string UIname)
  479. {
  480. if (!s_UIs.ContainsKey(UIname))
  481. {
  482. //Debug.Log("!ContainsKey " + UIname);
  483. return null;
  484. }
  485. else
  486. {
  487. if (s_UIs[UIname].Count == 0)
  488. {
  489. //Debug.Log("s_UIs[UIname].Count == 0");
  490. return null;
  491. }
  492. else
  493. {
  494. //默认返回最后创建的那一个
  495. return s_UIs[UIname][s_UIs[UIname].Count - 1];
  496. }
  497. }
  498. }
  499. public static UIBase GetUIBaseByEventKey(string eventKey)
  500. {
  501. string UIkey = eventKey.Split('.')[0];
  502. string[] keyArray = UIkey.Split('_');
  503. string uiEventKey = "";
  504. UIBase uiTmp = null;
  505. for (int i = 0; i < keyArray.Length; i++)
  506. {
  507. if(i == 0)
  508. {
  509. uiEventKey = keyArray[0];
  510. uiTmp = GetUIWindowByEventKey(uiEventKey);
  511. }
  512. else
  513. {
  514. uiEventKey += "_" + keyArray[i];
  515. uiTmp = uiTmp.GetItemByKey(uiEventKey);
  516. }
  517. Debug.Log("uiEventKey " + uiEventKey);
  518. }
  519. return uiTmp;
  520. }
  521. static Regex uiKey = new Regex(@"(\S+)\d+");
  522. static UIWindowBase GetUIWindowByEventKey(string eventKey)
  523. {
  524. string UIname = uiKey.Match(eventKey).Groups[1].Value;
  525. if (!s_UIs.ContainsKey(UIname))
  526. {
  527. throw new Exception("UIManager: GetUIWindowByEventKey error dont find UI name: ->" + eventKey + "<- " + UIname);
  528. }
  529. List<UIWindowBase> list = s_UIs[UIname];
  530. for (int i = 0; i < list.Count; i++)
  531. {
  532. if(list[i].UIEventKey == eventKey)
  533. {
  534. return list[i];
  535. }
  536. }
  537. throw new Exception("UIManager: GetUIWindowByEventKey error dont find UI name: ->" + eventKey + "<- " + UIname);
  538. }
  539. static bool GetIsExits(UIWindowBase UI)
  540. {
  541. if (!s_UIs.ContainsKey(UI.name))
  542. {
  543. return false;
  544. }
  545. else
  546. {
  547. return s_UIs[UI.name].Contains(UI);
  548. }
  549. }
  550. static void AddUI(UIWindowBase UI)
  551. {
  552. if (!s_UIs.ContainsKey(UI.name))
  553. {
  554. s_UIs.Add(UI.name, new List<UIWindowBase>());
  555. }
  556. s_UIs[UI.name].Add(UI);
  557. UI.Show();
  558. }
  559. static void RemoveUI(UIWindowBase UI)
  560. {
  561. if (UI == null)
  562. {
  563. throw new Exception("UIManager: RemoveUI error UI is null: !");
  564. }
  565. if (!s_UIs.ContainsKey(UI.name))
  566. {
  567. throw new Exception("UIManager: RemoveUI error dont find UI name: ->" + UI.name + "<- " + UI);
  568. }
  569. if (!s_UIs[UI.name].Contains(UI))
  570. {
  571. throw new Exception("UIManager: RemoveUI error dont find UI: ->" + UI.name + "<- " + UI);
  572. }
  573. else
  574. {
  575. s_UIs[UI.name].Remove(UI);
  576. }
  577. }
  578. static int GetUIID(string UIname)
  579. {
  580. if (!s_UIs.ContainsKey(UIname))
  581. {
  582. return 0;
  583. }
  584. else
  585. {
  586. int id = s_UIs[UIname].Count;
  587. for (int i = 0; i < s_UIs[UIname].Count; i++)
  588. {
  589. if(s_UIs[UIname][i].UIID == id)
  590. {
  591. id++;
  592. i = 0;
  593. }
  594. }
  595. return id;
  596. }
  597. }
  598. public static int GetNormalUICount()
  599. {
  600. return UIStackManager.m_normalStack.Count;
  601. }
  602. #endregion
  603. #region 隐藏UI列表的管理
  604. /// <summary>
  605. /// 删除所有隐藏的UI
  606. /// </summary>
  607. public static void DestroyAllHideUI()
  608. {
  609. foreach (List<UIWindowBase> uis in s_hideUIs.Values)
  610. {
  611. for (int i = 0; i < uis.Count; i++)
  612. {
  613. UISystemEvent.Dispatch(uis[i], UIEvent.OnDestroy); //派发OnDestroy事件
  614. try
  615. {
  616. uis[i].Dispose();
  617. }
  618. catch (Exception e)
  619. {
  620. Debug.LogError("OnDestroy :" + e.ToString());
  621. }
  622. GameObjectManager.DestroyGameObjectByPool(uis[i].gameObject);
  623. }
  624. }
  625. s_hideUIs.Clear();
  626. }
  627. public static T GetHideUI<T>() where T:UIWindowBase
  628. {
  629. string UIname = typeof(T).Name;
  630. return (T)GetHideUI(UIname);
  631. }
  632. /// <summary>
  633. /// 获取一个隐藏的UI,如果有多个同名UI,则返回最后创建的那一个
  634. /// </summary>
  635. /// <param name="UIname">UI名</param>
  636. /// <returns></returns>
  637. public static UIWindowBase GetHideUI(string UIname)
  638. {
  639. if (!s_hideUIs.ContainsKey(UIname))
  640. {
  641. return null;
  642. }
  643. else
  644. {
  645. if (s_hideUIs[UIname].Count == 0)
  646. {
  647. return null;
  648. }
  649. else
  650. {
  651. UIWindowBase ui = s_hideUIs[UIname][s_hideUIs[UIname].Count - 1];
  652. //默认返回最后创建的那一个
  653. return ui;
  654. }
  655. }
  656. }
  657. static bool GetIsExitsHide(UIWindowBase UI)
  658. {
  659. if (!s_hideUIs.ContainsKey(UI.name))
  660. {
  661. return false;
  662. }
  663. else
  664. {
  665. return s_hideUIs[UI.name].Contains(UI);
  666. }
  667. }
  668. static void AddHideUI(UIWindowBase UI)
  669. {
  670. if (!s_hideUIs.ContainsKey(UI.name))
  671. {
  672. s_hideUIs.Add(UI.name, new List<UIWindowBase>());
  673. }
  674. s_hideUIs[UI.name].Add(UI);
  675. UI.Hide();
  676. }
  677. static void RemoveHideUI(UIWindowBase UI)
  678. {
  679. if (UI == null)
  680. {
  681. throw new Exception("UIManager: RemoveUI error l_UI is null: !");
  682. }
  683. if (!s_hideUIs.ContainsKey(UI.name))
  684. {
  685. throw new Exception("UIManager: RemoveUI error dont find: " + UI.name + " " + UI);
  686. }
  687. if (!s_hideUIs[UI.name].Contains(UI))
  688. {
  689. throw new Exception("UIManager: RemoveUI error dont find: " + UI.name + " " + UI);
  690. }
  691. else
  692. {
  693. s_hideUIs[UI.name].Remove(UI);
  694. }
  695. }
  696. #endregion
  697. }
  698. #region UI事件 代理 枚举
  699. /// <summary>
  700. /// UI回调
  701. /// </summary>
  702. /// <param name="objs"></param>
  703. public delegate void UICallBack(UIWindowBase UI, params object[] objs);
  704. public delegate void UIAnimCallBack(UIWindowBase UIbase, UICallBack callBack, params object[] objs);
  705. public enum UIType
  706. {
  707. GameUI=0,
  708. Fixed=1,
  709. Normal=2,
  710. TopBar=3,
  711. PopUp=4,
  712. }
  713. public enum UIEvent
  714. {
  715. OnOpen,
  716. OnOpened,
  717. OnClose,
  718. OnClosed,
  719. OnHide,
  720. OnShow,
  721. OnInit,
  722. OnDestroy,
  723. OnRefresh,
  724. OnStartEnterAnim,
  725. OnCompleteEnterAnim,
  726. OnStartExitAnim,
  727. OnCompleteExitAnim,
  728. }
  729. #endregion