UIManager.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Reflection;
  5. using Core.Audio;
  6. using Core.Event.Event;
  7. using Core.UI.UTool;
  8. using Fort23.Core;
  9. using Fort23.UTool;
  10. using UnityEngine;
  11. using UnityEngine.Events;
  12. using UnityEngine.EventSystems;
  13. using UnityEngine.UI;
  14. using Utility;
  15. using EventSystem = UnityEngine.EventSystems.EventSystem;
  16. namespace Fort23.Mono
  17. {
  18. public enum UILayer
  19. {
  20. Bottom, //最底层UI(主界面)
  21. Middle, //中间UI(各种Panel)
  22. Top, //最顶层UI节点
  23. Loading, // 加载界面
  24. }
  25. /// <summary>
  26. /// 销毁类型
  27. /// </summary>
  28. public enum UIDestroyType
  29. {
  30. DelayDestroy,
  31. ImmediatelyDestroy,
  32. NotDestroy,
  33. }
  34. /// <summary>
  35. /// 如果有同时弹出多个UI界面冲突的地方,推荐用async/await的方法一次操作,这样就不用单独去为了适配打开多个UI的需求而改动太多的代码(主要是这样改动会牺牲大部分情况下的性能)
  36. /// </summary>
  37. public class UIManager : Entity
  38. {
  39. public static UIManager Instance { get; set; }
  40. public readonly Material uiGray = new Material(Shader.Find("MyShader/UIImageGray"));
  41. // public RectTransform UIRootTransform;
  42. public Vector2 sizeDelta;
  43. public EventSystem current;
  44. /// <summary>
  45. /// 父节点(InitClip)
  46. /// </summary>
  47. private Transform _parent;
  48. /// <summary>
  49. /// 所有展示BG的ui
  50. /// </summary>
  51. public List<UIPanel> AllShowBGUIs = new List<UIPanel>();
  52. /// <summary>
  53. /// 顶部ui列表 可以通过导航栏跳转的界面
  54. /// </summary>
  55. public List<UIPanel> TopUIPanels = new List<UIPanel>();
  56. /// <summary>
  57. /// 所有top层ui
  58. /// </summary>
  59. public List<UIPanel> NoFocusTopUIPanels = new List<UIPanel>();
  60. /// <summary>
  61. /// 弹窗ui
  62. /// </summary>
  63. public List<UIPanel> popUIPanels = new List<UIPanel>();
  64. /// <summary>
  65. /// 预先定好的几个层,数量和UILayer对应
  66. /// </summary>
  67. // public Canvas[] canvases = new Canvas[3];
  68. public Camera UICamera;
  69. public Canvas Canvas;
  70. public Transform[] UILayers = new Transform[4];
  71. /// <summary>
  72. /// 当前打开的ui
  73. /// </summary>
  74. public UIPanel currOpenPanel;
  75. /// <summary>
  76. /// UI布局大小
  77. /// </summary>
  78. private Vector2 UIScale;
  79. private BetterList<UIPanel> _lastShowPanel = new BetterList<UIPanel>();
  80. private Graphic currDeapthGraphic;
  81. /// <summary>
  82. /// 需要销毁的UI
  83. /// </summary>
  84. public Dictionary<string, UIPanel> destroyUI = new Dictionary<string, UIPanel>();
  85. public CustomCameraStack CurrCustomCameraStack
  86. {
  87. get { return _currCustomCameraStack; }
  88. set
  89. {
  90. _currCustomCameraStack = value;
  91. RefreshFull();
  92. }
  93. }
  94. public void CleanLastShowPanel()
  95. {
  96. _lastShowPanel.Clear();
  97. }
  98. private CustomCameraStack _currCustomCameraStack;
  99. /// <summary>
  100. /// 屏蔽字库
  101. /// </summary>
  102. public string MaskWordData;
  103. /// <summary>
  104. /// 展示文字提示长度
  105. /// </summary>
  106. public int ShowTextCount;
  107. /// <summary>
  108. /// 展示文字提示最大长度
  109. /// </summary>
  110. public int ShowTextMaxCount = 1;
  111. /// <summary>
  112. /// 上一个界面
  113. /// </summary>
  114. public UIPanel LastUIPanel;
  115. private Type BackgroundPanelType;
  116. [CustomMethod(CustomMethodType.Awake)]
  117. public async void Awake(Transform parent)
  118. {
  119. Instance = this;
  120. _parent = parent;
  121. }
  122. public async CTask InitUI()
  123. {
  124. UGUIIamgeTool.SpriteLoad = new UISpriteLoad();
  125. if (Canvas == null)
  126. {
  127. AssetHandle assetBundle =
  128. await AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>("Canvas.prefab");
  129. GameObject prefab = assetBundle.AssetObject<GameObject>();
  130. prefab.SetActive(false);
  131. // UIRootTransform = prefab.GetComponent<RectTransform>();
  132. sizeDelta = prefab.GetComponent<RectTransform>().sizeDelta;
  133. // if (1.0f * Screen.width / Screen.height < 1334f / 750f)
  134. // {
  135. // sizeDelta = new Vector2(1334, 750);
  136. // }
  137. // return;
  138. Canvas = prefab.GetComponent<Canvas>();
  139. prefab.transform.SetParent(_parent);
  140. UILayers[0] = prefab.transform.GetChild(0);
  141. UILayers[1] = prefab.transform.GetChild(1);
  142. UILayers[2] = prefab.transform.GetChild(2);
  143. UILayers[3] = prefab.transform.GetChild(3);
  144. UICamera = prefab.transform.GetComponentInChildren<Camera>();
  145. }
  146. current = EventSystem.current;
  147. Assembly assembly = Assembly.Load("Fort23.Mono");
  148. BackgroundPanelType = assembly.GetType(" Fort23.Mono.BackgroundPanel");
  149. // if (MaskWordData == null)
  150. // {
  151. // AssetHandle assetBundle =
  152. // await AssetBundleLoadManager.Instance.LoadAssetAsyncTask<TextAsset>("guofu.txt");
  153. // TextAsset text = assetBundle.AssetObject<TextAsset>();
  154. // MaskWordData = text.text;
  155. // assetBundle.Release();
  156. // }
  157. }
  158. public RectTransform GetLayer(UILayer layer)
  159. {
  160. try
  161. {
  162. int index = (int)layer;
  163. return (RectTransform)UILayers[index];
  164. }
  165. catch (Exception e)
  166. {
  167. Console.WriteLine(e);
  168. throw;
  169. }
  170. }
  171. public void SetGray(GameObject gameObject, bool isGray, bool isChildGray = false)
  172. {
  173. if (isChildGray)
  174. {
  175. Graphic[] graphics = gameObject.transform.GetComponentsInChildren<Graphic>();
  176. for (int i = 0; i < graphics.Length; i++)
  177. {
  178. if (isGray)
  179. {
  180. graphics[i].material = uiGray;
  181. }
  182. else
  183. {
  184. graphics[i].material = graphics[i].defaultMaterial;
  185. }
  186. }
  187. }
  188. else
  189. {
  190. Graphic graphic = gameObject.GetComponent<Graphic>();
  191. if (isGray)
  192. {
  193. graphic.material = uiGray;
  194. }
  195. else
  196. {
  197. graphic.material = graphic.defaultMaterial;
  198. }
  199. }
  200. }
  201. public void SetEventSystemEnable(bool value)
  202. {
  203. if (current != null)
  204. current.enabled = value;
  205. }
  206. [CustomMethod(CustomMethodType.Update)]
  207. public async void Update()
  208. {
  209. if (currDeapthGraphic != null)
  210. {
  211. UGUIIamgeTool.minDepth = currDeapthGraphic.canvasRenderer.absoluteDepth;
  212. UGUIIamgeTool.renderOrder = currDeapthGraphic.canvas.renderOrder;
  213. }
  214. else
  215. {
  216. UGUIIamgeTool.minDepth = -1;
  217. UGUIIamgeTool.renderOrder = 0;
  218. }
  219. if (Input.GetMouseButtonUp(0) && UILayers != null && UICamera != null)
  220. {
  221. Vector3 pos = UICamera.ScreenToWorldPoint(Input.mousePosition);
  222. GObjectPool.Instance.FetchAsync<ParticleSystemPool>("fx_ui_click.prefab",
  223. delegate(ParticleSystemPool pool)
  224. {
  225. if (pool != null)
  226. {
  227. Transform t = UILayers[^1];
  228. pool.transform.SetParent(t);
  229. pool.transform.position = new Vector3(pos.x, pos.y, t.transform.position.z);
  230. }
  231. });
  232. }
  233. }
  234. public Vector2 WorldToUIWorld(Vector3 worldPos)
  235. {
  236. // Vector3 worldPos = harmReturnInfo.target.combatHeroEntity.combatHeroGameObject.hpTransform.position;
  237. Vector3 p = CurrCustomCameraStack.camera.WorldToScreenPoint(worldPos);
  238. Vector3 p2 = UICamera.ScreenToWorldPoint(p);
  239. return p2;
  240. }
  241. public Vector3 UIWorldToWorld(Vector3 worldPos)
  242. {
  243. // Vector3 worldPos = harmReturnInfo.target.combatHeroEntity.combatHeroGameObject.hpTransform.position;
  244. Vector3 p = UICamera.WorldToScreenPoint(worldPos);
  245. p.z = 20;
  246. Vector3 p2 = CurrCustomCameraStack.camera.ScreenToWorldPoint(p);
  247. return p2;
  248. }
  249. /// <summary>
  250. /// 隐藏当前全部的UIPanel(只是不显示,不是销毁) 排除不在隐藏之列的UI
  251. /// </summary>
  252. public void HindCurrAllShowPanel()
  253. {
  254. if (_lastShowPanel.Count > 0)
  255. {
  256. return;
  257. }
  258. _lastShowPanel.Clear();
  259. UIPanel[] allShowPanel = GetComponentAll<UIPanel>();
  260. for (int i = 0; i < allShowPanel.Length; i++)
  261. {
  262. if (allShowPanel[i].GObjectPoolInterface.activeSelf)
  263. {
  264. allShowPanel[i].GObjectPoolInterface.SetActive(false);
  265. _lastShowPanel.Add(allShowPanel[i]);
  266. }
  267. }
  268. }
  269. public async CTask ShowLastHindAllShowPanel()
  270. {
  271. for (int i = 0; i < _lastShowPanel.Count; i++)
  272. {
  273. if (_lastShowPanel[i].GObjectPoolInterface != null)
  274. {
  275. _lastShowPanel[i].GObjectPoolInterface.SetActive(true);
  276. }
  277. }
  278. // if (_lastShowPanel.Contains(TopUIPanels[^1]))
  279. // {
  280. // _lastShowPanel.Clear();
  281. // if (TopUIPanels[^1].isShow)
  282. // {
  283. // await TopUIPanels[^1].GetFocus();
  284. // }
  285. // }
  286. _lastShowPanel.Clear();
  287. }
  288. public async CTask<UIPanel> LoadAndOpenPanel(Type uipsnelType, Action<UIPanel> callback,
  289. UILayer layer = UILayer.Middle,
  290. bool isFocus = true, object[] uiData = null, bool isShowBG = false, bool isFullUI = false,
  291. bool isActiveAnima = true)
  292. {
  293. try
  294. {
  295. Type type;
  296. // current = EventSystem.current;
  297. type = uipsnelType;
  298. UIPanel uiPanel;
  299. // 获取UI绑定属性
  300. UIBindingAttribute uiBindingAttribute =
  301. type.GetCustomAttribute(typeof(UIBindingAttribute)) as UIBindingAttribute;
  302. if (uiBindingAttribute == null)
  303. {
  304. LogTool.Error($"类型{type.Name}没有添加UIBindingAttribute!");
  305. return null;
  306. }
  307. using (await CoroutineLockComponent.Instance.Wait(uiBindingAttribute.prefab))
  308. {
  309. if (current != null)
  310. {
  311. SetEventSystemEnable(false);
  312. }
  313. // 不可以重复打开Panel,但是可以把上一个拿来使用。
  314. if (!Components.ContainsKey(type))
  315. {
  316. GameObject gameObjectPool = await FetchUI(uiBindingAttribute, GetLayer(layer));
  317. if (gameObjectPool == null)
  318. return null;
  319. uiPanel = AddComponent<GameObject>(type, gameObjectPool, false) as UIPanel;
  320. uiPanel.uiName = uiBindingAttribute.prefab;
  321. uiPanel.isFocus = isFocus;
  322. await uiPanel.SetUIGameObject(gameObjectPool);
  323. gameObjectPool.SetActive(false);
  324. }
  325. else
  326. {
  327. uiPanel = GetComponent(type) as UIPanel;
  328. if (uiPanel.DestroyTimerEntity != null)
  329. {
  330. TimerComponent.Instance.Remove(uiPanel.DestroyTimerEntity.ID);
  331. uiPanel.DestroyTimerEntity.Destroy();
  332. }
  333. destroyUI.Remove(uiBindingAttribute.prefab);
  334. }
  335. Assembly assembly = Assembly.Load("Fort23.Mono");
  336. Type combatPanel = assembly.GetType(" Fort23.Mono.CombatPanel");
  337. if (uiPanel.isAddStack && uiPanel.GetType() != combatPanel)
  338. {
  339. EventManager.Instance.Dispatch(CustomEventType.CancelEvent, null);
  340. }
  341. uiPanel.isFullUI = isFullUI;
  342. // 等待数据准备好才初始化UI
  343. if (await uiPanel.AsyncInit(uiData))
  344. {
  345. if (uiPanel.isAddStack)
  346. {
  347. if (uiPanel.IsBreadcrumbBarPanel) //打开界面之前判断是否已经在堆栈当中 如果是就移除此界面往后的堆栈 保持他时在堆栈的最上方
  348. {
  349. if (TopUIPanels.Contains(uiPanel))
  350. {
  351. int index = TopUIPanels.IndexOf(uiPanel);
  352. int count = TopUIPanels.Count - index;
  353. for (int i = index + 1; i < TopUIPanels.Count; i++)
  354. {
  355. if (TopUIPanels[i].isShow)
  356. {
  357. HideUIUIPanel(TopUIPanels[i]);
  358. }
  359. }
  360. TopUIPanels.RemoveRange(index, count);
  361. }
  362. }
  363. AddTopStack(uiPanel);
  364. }
  365. if (layer == UILayer.Top && !NoFocusTopUIPanels.Contains(uiPanel))
  366. NoFocusTopUIPanels.Add(uiPanel);
  367. uiPanel.isActiveAnima = isActiveAnima;
  368. await uiPanel.Open();
  369. // AudioManager.Instance.PlayAudio("openui.wav");
  370. // if (currOpenPanel.add)
  371. // {
  372. // currOpenPanel = uiPanel;
  373. // }
  374. if (current != null)
  375. {
  376. SetEventSystemEnable(true);
  377. }
  378. await TimerComponent.Instance.WaitAsync(1); //等待一帧 让渲染完成后在执行完成逻辑
  379. callback?.Invoke(uiPanel);
  380. RefreshFull();
  381. // if (isShowBG)
  382. // {
  383. // uiPanel.IsShowCustomBGPanel = true;
  384. // if (!AllShowBGUIs.Contains(uiPanel))
  385. // AllShowBGUIs.Add(uiPanel);
  386. // await GetBackgroundPanel(uiPanel, GetLayer(layer));
  387. // }
  388. return uiPanel;
  389. }
  390. else
  391. {
  392. if (current != null)
  393. {
  394. SetEventSystemEnable(true);
  395. }
  396. // 界面数据没准备好,因此本次操作将被销毁
  397. LogTool.Log($"数据准备失败,请检查{type.Name}的Init方法中的逻辑");
  398. // ShowTips($"数据准备失败,请检查{buildType.Name}的Init方法中的逻辑");
  399. uiPanel.Close();
  400. return null;
  401. }
  402. }
  403. }
  404. catch (Exception e)
  405. {
  406. if (current != null)
  407. {
  408. SetEventSystemEnable(true);
  409. }
  410. LogTool.Error(uipsnelType.ToString() + " " + e.Message);
  411. LogTool.Exception(e);
  412. return null;
  413. }
  414. }
  415. /// <summary>
  416. /// 用窗口打开某个界面(不可重复的预设,适用于一切带有关闭按钮的窗口UI)
  417. /// </summary>
  418. /// <param name="callback"> ui加载完成时的回调</param>
  419. /// <param name="layer"> ui需要显示在那一层,现在分为3层</param>
  420. /// <param name="isFocus"> 是否时需要获取焦点</param>
  421. /// <param name="uiData">打开UI时的透传数据</param>
  422. /// <param name="isShowBG">是否需要显示统一的背板</param>
  423. /// isFullUI 是否是全面屏UI
  424. /// <typeparam name="T"></typeparam>
  425. /// <returns></returns>
  426. public async CTask<T> LoadAndOpenPanel<T>(Action<T> callback, UILayer layer = UILayer.Middle,
  427. bool isFocus = true, object[] uiData = null, bool isShowBG = false, bool isFullUI = false,
  428. bool isActiveAnima = true)
  429. where T : UIPanel, new()
  430. {
  431. try
  432. {
  433. Type type;
  434. // current = EventSystem.current;
  435. type = typeof(T);
  436. T uiPanel;
  437. // 获取UI绑定属性
  438. UIBindingAttribute uiBindingAttribute =
  439. type.GetCustomAttribute(typeof(UIBindingAttribute)) as UIBindingAttribute;
  440. if (uiBindingAttribute == null)
  441. {
  442. LogTool.Error($"类型{type.Name}没有添加UIBindingAttribute!");
  443. return null;
  444. }
  445. // if (isFocus)
  446. // {
  447. // if (currOpenPanel != null)
  448. // {
  449. // if (currOpenPanel.isShow)
  450. // {
  451. // await currOpenPanel.LoseFocus();
  452. // currOpenPanel = null;
  453. // }
  454. // else
  455. // {
  456. // currOpenPanel = null;
  457. // }
  458. // }
  459. // }
  460. using (await CoroutineLockComponent.Instance.Wait(uiBindingAttribute.prefab))
  461. {
  462. if (current != null)
  463. {
  464. SetEventSystemEnable(false);
  465. // current.isClose = true;
  466. }
  467. // 不可以重复打开Panel,但是可以把上一个拿来使用。
  468. if (!Components.ContainsKey(type))
  469. {
  470. GameObject gameObjectPool = await FetchUI(uiBindingAttribute, GetLayer(layer));
  471. if (gameObjectPool == null)
  472. return null;
  473. uiPanel = AddComponent<T, GameObject>(gameObjectPool, false);
  474. uiPanel.uiName = uiBindingAttribute.prefab;
  475. uiPanel.isFocus = isFocus;
  476. await uiPanel.SetUIGameObject(gameObjectPool);
  477. gameObjectPool.SetActive(false);
  478. }
  479. else
  480. {
  481. uiPanel = GetComponent<T>();
  482. if (uiPanel.DestroyTimerEntity != null)
  483. {
  484. TimerComponent.Instance.Remove(uiPanel.DestroyTimerEntity.ID);
  485. uiPanel.DestroyTimerEntity.Destroy();
  486. }
  487. destroyUI.Remove(uiBindingAttribute.prefab);
  488. }
  489. Assembly assembly = Assembly.Load("Fort23.Mono");
  490. Type combatPanel = assembly.GetType(" Fort23.Mono.CombatPanel");
  491. if (uiPanel.isAddStack && uiPanel.GetType() != combatPanel)
  492. {
  493. EventManager.Instance.Dispatch(CustomEventType.CancelEvent, null);
  494. }
  495. uiPanel.isFullUI = isFullUI;
  496. if (isShowBG)
  497. {
  498. uiPanel.IsShowCustomBGPanel = true;
  499. if (!AllShowBGUIs.Contains(uiPanel))
  500. AllShowBGUIs.Add(uiPanel);
  501. await GetBackgroundPanel(uiPanel, GetLayer(layer));
  502. }
  503. // 等待数据准备好才初始化UI
  504. if (await uiPanel.AsyncInit(uiData))
  505. {
  506. if (uiPanel.isAddStack)
  507. {
  508. if (uiPanel.IsBreadcrumbBarPanel) //打开界面之前判断是否已经在堆栈当中 如果是就移除此界面往后的堆栈 保持他时在堆栈的最上方
  509. {
  510. if (TopUIPanels.Contains(uiPanel))
  511. {
  512. int index = TopUIPanels.IndexOf(uiPanel);
  513. int count = TopUIPanels.Count - index;
  514. for (int i = index + 1; i < TopUIPanels.Count; i++)
  515. {
  516. if (TopUIPanels[i].isShow)
  517. {
  518. HideUIUIPanel(TopUIPanels[i]);
  519. }
  520. }
  521. TopUIPanels.RemoveRange(index, count);
  522. }
  523. }
  524. AddTopStack(uiPanel);
  525. }
  526. if (layer == UILayer.Top && !NoFocusTopUIPanels.Contains(uiPanel))
  527. NoFocusTopUIPanels.Add(uiPanel);
  528. uiPanel.isActiveAnima = isActiveAnima;
  529. await uiPanel.Open();
  530. if (current != null)
  531. {
  532. SetEventSystemEnable(true);
  533. }
  534. await TimerComponent.Instance.WaitAsync(1); //等待一帧 让渲染完成后在执行完成逻辑
  535. callback?.Invoke(uiPanel);
  536. RefreshFull();
  537. // if (isShowBG)
  538. // {
  539. //
  540. // uiPanel.IsShowCustomBGPanel = true;
  541. // if (!AllShowBGUIs.Contains(uiPanel))
  542. // AllShowBGUIs.Add(uiPanel);
  543. // await GetBackgroundPanel(uiPanel, GetLayer(layer));
  544. // }
  545. return uiPanel;
  546. }
  547. else
  548. {
  549. if (current != null)
  550. {
  551. SetEventSystemEnable(true);
  552. }
  553. // 界面数据没准备好,因此本次操作将被销毁
  554. LogTool.Log($"数据准备失败,请检查{type.Name}的Init方法中的逻辑");
  555. uiPanel.Close();
  556. return null;
  557. }
  558. }
  559. }
  560. catch (Exception e)
  561. {
  562. if (current != null)
  563. {
  564. SetEventSystemEnable(true);
  565. }
  566. LogTool.Error(typeof(T).ToString() + " " + e.Message);
  567. LogTool.Exception(e);
  568. return null;
  569. }
  570. }
  571. public void RefreshFull()
  572. {
  573. Graphic min = null;
  574. UIPanel[] allPanel = GetComponentAll<UIPanel>();
  575. bool isFull = false;
  576. if (allPanel != null)
  577. {
  578. for (int i = 0; i < allPanel.Length; i++)
  579. {
  580. UIPanel panel = allPanel[i];
  581. if (panel != null && panel.minDepth != null && !panel.IsClose && panel.isShow &&
  582. panel.GObjectPoolInterface.activeSelf && panel.isFullUI)
  583. {
  584. if (min == null)
  585. {
  586. min = panel.minDepth;
  587. continue;
  588. }
  589. if (min != null && panel.minDepth.canvasRenderer.absoluteDepth >
  590. min.canvasRenderer.absoluteDepth)
  591. {
  592. min = panel.minDepth;
  593. }
  594. }
  595. }
  596. if (min != null)
  597. {
  598. UGUIIamgeTool.minDepth = min.canvasRenderer.absoluteDepth;
  599. UGUIIamgeTool.renderOrder = min.canvas.renderOrder;
  600. }
  601. else
  602. {
  603. UGUIIamgeTool.minDepth = -1;
  604. UGUIIamgeTool.renderOrder = 0;
  605. }
  606. currDeapthGraphic = min;
  607. for (int i = 0; i < allPanel.Length; i++)
  608. {
  609. UIPanel panel = allPanel[i];
  610. if (panel != null && !panel.IsClose && panel.isShow && panel.GObjectPoolInterface.activeSelf &&
  611. panel.isFullUI)
  612. {
  613. isFull = true;
  614. break;
  615. }
  616. }
  617. }
  618. RefreshFullEventData refreshFullEventData = RefreshFullEventData.Create();
  619. refreshFullEventData.isFullShow = isFull;
  620. EventManager.Instance.Dispatch(CustomEventType.RefreshFull, refreshFullEventData);
  621. if (_currCustomCameraStack == null)
  622. {
  623. // URPTool.Instance.IsNotRenderMainCamera = false;
  624. return;
  625. }
  626. if (isFull)
  627. {
  628. AudioManager.Instance.SetBgmValue(0.5f);
  629. }
  630. else
  631. {
  632. AudioManager.Instance.SetBgmValue(1f);
  633. }
  634. // URPTool.Instance.IsNotRenderMainCamera = isFull;
  635. }
  636. /// <summary>
  637. /// 关闭最上层堆栈的uiPanel
  638. /// </summary>
  639. public void HideTopPanel()
  640. {
  641. if (TopUIPanels.Count > 0)
  642. {
  643. if (TopUIPanels[^1] != null)
  644. {
  645. TopUIPanels[^1].Hide();
  646. }
  647. }
  648. }
  649. /// <summary>
  650. /// 加入topUI堆栈
  651. /// </summary>
  652. public void AddTopStack(UIPanel uiPanel)
  653. {
  654. if (!TopUIPanels.Contains(uiPanel))
  655. {
  656. TopUIPanels.Add(uiPanel);
  657. uiPanel.IsBreadcrumbBarPanel = true;
  658. }
  659. }
  660. /// <summary>
  661. /// 弹出堆栈
  662. /// </summary>
  663. public void RemoveTopStack(UIPanel uiPanel)
  664. {
  665. if (TopUIPanels.Contains(uiPanel))
  666. {
  667. TopUIPanels.Remove(uiPanel);
  668. }
  669. }
  670. /// <summary>
  671. /// 关闭最顶部的ui
  672. /// </summary>
  673. public UIPanel CloseTopUI()
  674. {
  675. if (TopUIPanels.Count > 0)
  676. {
  677. UIPanel uiPanel = TopUIPanels[^1];
  678. uiPanel.IsBreadcrumbBarPanel = false; //返回关闭的时候将它设置为false 表示可以被删除
  679. HideUIUIPanel(uiPanel);
  680. return uiPanel;
  681. }
  682. return null;
  683. }
  684. /// <summary>
  685. /// 隐藏所有堆栈的ui
  686. /// </summary>
  687. public void HideAllStackUI()
  688. {
  689. for (var i = 0; i < TopUIPanels.Count; i++)
  690. {
  691. HideUIUIPanel(TopUIPanels[i]);
  692. }
  693. }
  694. /// <summary>
  695. /// 打开堆栈最上方
  696. /// </summary>
  697. public async CTask OpenTopUI()
  698. {
  699. if (TopUIPanels.Count > 0)
  700. {
  701. UIPanel uiPanel = TopUIPanels[^1];
  702. // currOpenPanel = uiPanel;
  703. await uiPanel.Show();
  704. }
  705. }
  706. public Material UISpineMaterial;
  707. /// <summary>
  708. /// 创建组件 可重复使用的(这个方法,只是提供gameObject和脚本的绑定,没有经过池子,因此gameObject依然还挂在原来的预设上)
  709. /// </summary>
  710. /// <param name="root">父节点</param>
  711. /// <typeparam name="T"></typeparam>
  712. /// <returns></returns>
  713. public async CTask<T> CreateGComponentForObject<T>(GameObject gameObject, Action<T> callback,
  714. RectTransform root = null,
  715. object[] uiData = null, bool isInstance = false, string poolName = null, bool isActiveAnima = true)
  716. where T : UIComponent, new()
  717. {
  718. try
  719. {
  720. Type type = typeof(T);
  721. // // 获取UI绑定属性
  722. UIBindingAttribute uiBindingAttribute =
  723. type.GetCustomAttribute(typeof(UIBindingAttribute)) as UIBindingAttribute;
  724. if (uiBindingAttribute == null)
  725. {
  726. LogTool.Error($"类型{type.Name}没有添加UIBindingAttribute!");
  727. return null;
  728. }
  729. GameObject newObject = gameObject;
  730. T gameObjectPool = null;
  731. if (isInstance)
  732. {
  733. string newPoolName = string.IsNullOrEmpty(poolName) ? gameObject.name + ".prefab" : poolName;
  734. gameObjectPool = GObjectPool.Instance.FetchAsyncForGameObject<T>(gameObject, newPoolName);
  735. newObject = gameObjectPool.own;
  736. // gameObjectPool.own.transform.SetParent(root);
  737. // newObject = GameObject.Instantiate(gameObject);
  738. }
  739. else
  740. {
  741. gameObjectPool = Activator.CreateInstance<T>();
  742. gameObjectPool.ActiveObj();
  743. // UIEventMono uiEventMono = newObject.GetComponent<UIEventMono>();
  744. // if (uiEventMono != null)
  745. // {
  746. // uiEventMono.Destory();
  747. // }
  748. }
  749. if (gameObjectPool == null)
  750. {
  751. return null;
  752. }
  753. gameObjectPool.SetGameObject(newObject);
  754. return await SetGComponentInfo(gameObjectPool, callback, root, uiData, isActiveAnima);
  755. }
  756. catch (Exception e)
  757. {
  758. LogTool.Exception(e);
  759. return null;
  760. }
  761. }
  762. /// <summary>
  763. /// 创建组件 可重复使用的
  764. /// </summary>
  765. /// <param name="root">父节点</param>
  766. /// <typeparam name="T"></typeparam>
  767. /// <returns></returns>
  768. public async CTask<T> CreateGComponent<T>(Action<T> callback, RectTransform root = null, object[] uiData = null,
  769. string poolName = null, Clock clock = null, bool isActive = true, bool isActiveAnima = true)
  770. where T : UIComponent, new()
  771. {
  772. try
  773. {
  774. Type type = typeof(T);
  775. // 获取UI绑定属性
  776. UIBindingAttribute uiBindingAttribute =
  777. type.GetCustomAttribute(typeof(UIBindingAttribute)) as UIBindingAttribute;
  778. if (uiBindingAttribute == null)
  779. {
  780. LogTool.Error($"类型{type.Name}没有添加UIBindingAttribute!");
  781. return null;
  782. }
  783. T gameObjectPool = await GObjectPool.Instance.FetchAsync<T>(uiBindingAttribute.prefab + ".prefab",
  784. poolName: poolName, clock: clock);
  785. if (gameObjectPool == null)
  786. {
  787. return default;
  788. }
  789. T cTask = await SetGComponentInfo(gameObjectPool, callback, root, uiData, isActiveAnima);
  790. gameObjectPool.own.SetActive(isActive);
  791. return cTask;
  792. }
  793. catch (Exception e)
  794. {
  795. LogTool.Exception(e);
  796. return null;
  797. }
  798. }
  799. /// <summary>
  800. /// 隐藏回收池子内的所有对象
  801. /// </summary>
  802. /// <param name="poolName"></param>
  803. /// <typeparam name="T"></typeparam>
  804. public void DormancyAllGComponent<T>(string poolName)
  805. {
  806. GObjectPool.Instance.DormancyPool<T>(poolName);
  807. }
  808. public void DormancyAllGComponent<T>()
  809. {
  810. Type type = typeof(T);
  811. // 获取UI绑定属性
  812. UIBindingAttribute uiBindingAttribute =
  813. type.GetCustomAttribute(typeof(UIBindingAttribute)) as UIBindingAttribute;
  814. if (uiBindingAttribute == null)
  815. {
  816. LogTool.Error($"类型{type.Name}没有添加UIBindingAttribute!");
  817. return;
  818. }
  819. string poolName = uiBindingAttribute.prefab + ".prefab";
  820. GObjectPool.Instance.DormancyPool<T>(poolName);
  821. }
  822. public void DormancyGComponent(IGObjectPoolInterface poolInterface)
  823. {
  824. if (poolInterface == null)
  825. {
  826. return;
  827. }
  828. if (string.IsNullOrEmpty(poolInterface.poolObjName))
  829. {
  830. poolInterface.DormancyObj();
  831. return;
  832. }
  833. GObjectPool.Instance.Recycle(poolInterface);
  834. }
  835. private async CTask<T> SetGComponentInfo<T>(T gameObjectPool, Action<T> callback, RectTransform root = null,
  836. object[] uiData = null, bool isActiveAnima = true) where T : UIComponent, new()
  837. {
  838. try
  839. {
  840. if (gameObjectPool == null)
  841. return null;
  842. RectTransform rectTransform = gameObjectPool.own.GetComponent<RectTransform>();
  843. if (root != null)
  844. {
  845. rectTransform.SetParent(root);
  846. rectTransform.SetAsLastSibling();
  847. rectTransform.anchoredPosition = Vector3.zero;
  848. rectTransform.localScale = Vector3.one;
  849. rectTransform.localEulerAngles = Vector3.zero;
  850. }
  851. gameObjectPool.isActiveAnima = isActiveAnima;
  852. await gameObjectPool.SetUIGameObject(gameObjectPool.own);
  853. if (await gameObjectPool.AsyncInit(uiData))
  854. {
  855. gameObjectPool.DelEvent(); //为了以防万一,先移除内部事件
  856. gameObjectPool.AddEvent();
  857. gameObjectPool.Show();
  858. // await TimerComponent.Instance.WaitAsync(1);
  859. callback?.Invoke(gameObjectPool);
  860. return gameObjectPool;
  861. }
  862. else
  863. {
  864. LogTool.Log($"数据准备失败,请检查{gameObjectPool.own.name}的Init方法中的逻辑");
  865. gameObjectPool.Close();
  866. return null;
  867. }
  868. }
  869. catch (Exception e)
  870. {
  871. LogTool.Exception(e);
  872. return null;
  873. }
  874. }
  875. public async CTask HideUIUIPanel<T>(UIDestroyType uiDestroyType = UIDestroyType.DelayDestroy,
  876. bool isBreadcrumbBarPanel = true) where T : UIPanel
  877. {
  878. UIPanel uiPanel = GetComponent<T>();
  879. if (uiPanel != null)
  880. {
  881. await HideUIUIPanel(uiPanel, uiDestroyType, isBreadcrumbBarPanel);
  882. }
  883. }
  884. /// <summary>
  885. /// 关闭UI
  886. /// </summary>
  887. /// <param name="uiPanel"></param>
  888. public async CTask HideUIUIPanel(UIPanel uiPanel, UIDestroyType uiDestroyType = UIDestroyType.DelayDestroy,
  889. bool isBreadcrumbBarPanel = true)
  890. {
  891. if (uiPanel == null)
  892. return;
  893. if (uiPanel.IsClose)
  894. {
  895. return;
  896. }
  897. if (uiPanel.IsShowCustomBGPanel) //如果是开了背景的界面关闭的时候将背景一起关闭
  898. {
  899. HideUIUIPanel(GetComponent(BackgroundPanelType) as UIPanel, UIDestroyType.NotDestroy);
  900. }
  901. // CloseTopUI();
  902. // OpenTopUI();
  903. if (uiPanel.IsBreadcrumbBarPanel &&
  904. uiPanel.isAddStack &&
  905. uiDestroyType != UIDestroyType.ImmediatelyDestroy) //如果显示导航栏的面板就只做隐藏 导航返回自动处理关闭
  906. {
  907. if (isBreadcrumbBarPanel)
  908. {
  909. uiPanel.IsBreadcrumbBarPanel = false;
  910. UIPanel uiPanel1 = CloseTopUI();
  911. if (uiPanel != null)
  912. {
  913. LastUIPanel = uiPanel1;
  914. await OpenTopUI();
  915. return;
  916. }
  917. }
  918. }
  919. if (!NoFocusTopUIPanels.Contains(uiPanel)) NoFocusTopUIPanels.Remove(uiPanel);
  920. uiPanel.Close();
  921. RemoveTopStack(uiPanel); //如果要删除界面判断是否在跳转堆栈 如果是则移除堆栈
  922. switch (uiDestroyType)
  923. {
  924. case UIDestroyType.DelayDestroy:
  925. if (!destroyUI.ContainsKey(uiPanel.uiName))
  926. {
  927. uiPanel.AddDelayDestroy();
  928. destroyUI.Add(uiPanel.uiName, uiPanel);
  929. }
  930. break;
  931. case UIDestroyType.ImmediatelyDestroy:
  932. DestroyUIPanel(uiPanel);
  933. break;
  934. case UIDestroyType.NotDestroy:
  935. break;
  936. }
  937. RefreshFull();
  938. }
  939. public void DestroyUIPanel(UIPanel uiPanel)
  940. {
  941. if (uiPanel.Parent == null)
  942. {
  943. return;
  944. }
  945. destroyUI.Remove(uiPanel.uiName);
  946. uiPanel.Parent.RemoveComponent(uiPanel);
  947. }
  948. private async CTask<GameObject> FetchUI(UIBindingAttribute uiBindingAttribute, Transform tf)
  949. {
  950. GameObjectPool assetBundle =
  951. await GObjectPool.Instance.FetchAsync<GameObjectPool>(uiBindingAttribute.prefab + ".prefab");
  952. GameObject gameObject = assetBundle.own;
  953. if (gameObject == null)
  954. return null;
  955. gameObject.transform.SetParent(tf);
  956. gameObject.transform.SetAsLastSibling();
  957. gameObject.transform.localScale = Vector3.one;
  958. return gameObject;
  959. }
  960. /// <summary>
  961. /// <summary>
  962. /// 屏幕转ui坐标
  963. /// </summary>
  964. /// <param name="rPosition"></param>
  965. /// <returns></returns>
  966. public Vector3 ScreenPointToLocalPointInRectangle(Vector2 rPosition)
  967. {
  968. RectTransform rRect = Instance.Canvas.GetComponent<RectTransform>();
  969. Vector3 lPosition = Instance.UICamera.ScreenToWorldPoint(rPosition);
  970. Vector4 l4Position =
  971. new Vector4(lPosition.x, lPosition.y, lPosition.z, 1); // unity默认转化v4,w是0,不会计算x和y的rect的偏移,所以这里要自己搞一下。
  972. lPosition = rRect.worldToLocalMatrix * l4Position;
  973. lPosition.z = 0;
  974. return lPosition;
  975. }
  976. /// <summary>
  977. /// ui组件添加自定义事件
  978. /// </summary>
  979. /// <param name="obj"></param>
  980. /// <param name="eventTriggerType"></param>
  981. /// <param name="callback"></param>
  982. public void AddCustomEventListener(UIBehaviour control, EventTriggerType type,
  983. UnityAction<BaseEventData> callback)
  984. {
  985. EventTrigger trigger = control.GetComponent<EventTrigger>();
  986. if (trigger == null)
  987. {
  988. trigger = control.gameObject.AddComponent<EventTrigger>();
  989. }
  990. EventTrigger.Entry entry = new EventTrigger.Entry();
  991. entry.eventID = type;
  992. entry.callback.AddListener(callback);
  993. trigger.triggers.Add(entry);
  994. }
  995. public override void Dispose()
  996. {
  997. base.Dispose();
  998. UGUIIamgeTool.renderOrder = 0;
  999. }
  1000. /// <summary>
  1001. /// 移除自定义事件
  1002. /// </summary>
  1003. /// <param name="control"></param>
  1004. /// <param name="type"></param>
  1005. /// <param name="callback"></param>
  1006. public void RemoveCustomEventListener(UIBehaviour control, EventTriggerType type,
  1007. UnityAction<BaseEventData> callback)
  1008. {
  1009. EventTrigger trigger = control.GetComponent<EventTrigger>();
  1010. if (trigger == null)
  1011. {
  1012. trigger = control.gameObject.AddComponent<EventTrigger>();
  1013. }
  1014. for (int i = 0; i < trigger.triggers.Count; i++)
  1015. {
  1016. if (trigger.triggers[i].eventID == type)
  1017. {
  1018. trigger.triggers[i].callback.RemoveListener(callback);
  1019. // Debug.Log("移除事件");
  1020. }
  1021. }
  1022. }
  1023. public GameObject GetOverUI(GameObject canvas)
  1024. {
  1025. PointerEventData pointerEventData = new PointerEventData(UnityEngine.EventSystems.EventSystem.current);
  1026. pointerEventData.position = Input.mousePosition;
  1027. GraphicRaycaster gr = canvas.GetComponent<GraphicRaycaster>();
  1028. List<RaycastResult> results = new List<RaycastResult>();
  1029. gr.Raycast(pointerEventData, results);
  1030. if (results.Count != 0)
  1031. {
  1032. return results[0].gameObject;
  1033. }
  1034. return null;
  1035. }
  1036. public Vector2 SetPopTipPosition(Vector3 pos, Vector2 sizeDelta)
  1037. {
  1038. Vector2 xy = sizeDelta / 2;
  1039. Vector2 vector2 = Canvas.GetComponent<RectTransform>().sizeDelta;
  1040. float x = vector2.x / 2;
  1041. float y = vector2.y / 2;
  1042. if (pos.x + xy.x >= x)
  1043. {
  1044. pos.x = x - xy.x;
  1045. }
  1046. else if (pos.x - xy.x <= -x)
  1047. {
  1048. pos.x = -x + xy.x;
  1049. }
  1050. if (pos.y + xy.y >= y)
  1051. {
  1052. pos.y = y - xy.y;
  1053. }
  1054. else if (pos.y - xy.y <= -y)
  1055. {
  1056. pos.y = -y + xy.y;
  1057. }
  1058. return pos;
  1059. }
  1060. /// <summary>
  1061. /// 设置数值文本的显示
  1062. /// </summary>
  1063. /// <param name="number"></param>
  1064. /// <returns></returns>
  1065. public string SetNumberTextShow(long number)
  1066. {
  1067. if (number > 1000000000000)
  1068. {
  1069. float n = number / 1000000000000f;
  1070. string str = "";
  1071. if (n > 100)
  1072. {
  1073. int n1 = (int)(n * 10);
  1074. n = n1 / 10f;
  1075. str = n.ToString(CultureInfo.InvariantCulture);
  1076. }
  1077. else
  1078. {
  1079. int n1 = (int)(n * 100);
  1080. n = n1 / 100f;
  1081. str = n.ToString(CultureInfo.InvariantCulture);
  1082. }
  1083. return str + "t";
  1084. }
  1085. if (number > 1000000000)
  1086. {
  1087. float n = number / 1000000000f;
  1088. string str = "";
  1089. if (n > 100)
  1090. {
  1091. int n1 = (int)(n * 10);
  1092. n = n1 / 10f;
  1093. str = n.ToString(CultureInfo.InvariantCulture);
  1094. }
  1095. else
  1096. {
  1097. int n1 = (int)(n * 100);
  1098. n = n1 / 100f;
  1099. str = n.ToString(CultureInfo.InvariantCulture);
  1100. }
  1101. return str + "b";
  1102. }
  1103. if (number > 1000000)
  1104. {
  1105. float n = number / 1000000f;
  1106. string str = "";
  1107. if (n > 100)
  1108. {
  1109. int n1 = (int)(n * 10);
  1110. n = n1 / 10f;
  1111. str = n.ToString(CultureInfo.InvariantCulture);
  1112. }
  1113. else
  1114. {
  1115. int n1 = (int)(n * 100);
  1116. n = n1 / 100f;
  1117. str = n.ToString(CultureInfo.InvariantCulture);
  1118. }
  1119. return str + "m";
  1120. }
  1121. if (number > 10000)
  1122. {
  1123. float n = number / 1000f;
  1124. string str = "";
  1125. if (n > 100)
  1126. {
  1127. int n1 = (int)(n * 10);
  1128. n = n1 / 10f;
  1129. str = n.ToString(CultureInfo.InvariantCulture);
  1130. }
  1131. else
  1132. {
  1133. int n1 = (int)(n * 100);
  1134. n = n1 / 100f;
  1135. str = n.ToString(CultureInfo.InvariantCulture);
  1136. }
  1137. return str + "k";
  1138. }
  1139. return number.ToString();
  1140. }
  1141. /// <summary>
  1142. /// 获取背景
  1143. /// </summary>
  1144. /// <returns></returns>
  1145. public async CTask<UIPanel> GetBackgroundPanel(UIPanel uiPanel, Transform parent)
  1146. {
  1147. UIPanel popupPanel;
  1148. if (GetComponent(BackgroundPanelType) == null)
  1149. {
  1150. popupPanel = await LoadAndOpenPanel(BackgroundPanelType, null, UILayer.Top, false, isFullUI: true);
  1151. }
  1152. else
  1153. {
  1154. popupPanel = Instance.GetComponent(BackgroundPanelType) as UIPanel;
  1155. }
  1156. popupPanel.transform.SetParent(parent, false);
  1157. popupPanel.transform.SetAsFirstSibling();
  1158. int index01 = uiPanel.GObjectPoolInterface.transform.GetSiblingIndex();
  1159. // popupPanel.transform.SetParent(parent, false);
  1160. popupPanel.transform.SetSiblingIndex(index01 - 1);
  1161. await popupPanel.Open();
  1162. return popupPanel;
  1163. }
  1164. /// <summary>
  1165. /// 设置背景在需要显示背景的ui下面
  1166. /// </summary>
  1167. public async void SetBackgroundPanel(UIPanel uiBase)
  1168. {
  1169. if (AllShowBGUIs.Contains(uiBase))
  1170. {
  1171. AllShowBGUIs.Remove(uiBase);
  1172. }
  1173. for (int i = AllShowBGUIs.Count - 1; i >= 0; i--)
  1174. {
  1175. if (AllShowBGUIs[i].IsShowCustomBGPanel) //从后往前如果需要展示bg 就展示 否则将bg放到最上方需要展示的ui后面
  1176. {
  1177. UIPanel popupPanel = await GetBackgroundPanel(AllShowBGUIs[i], AllShowBGUIs[i].transform.parent);
  1178. break;
  1179. }
  1180. }
  1181. }
  1182. /// <summary>
  1183. /// 每日是否提醒标记
  1184. /// </summary>
  1185. public enum ToDayDontShowTag
  1186. {
  1187. MjToDiamond = 0,
  1188. DiamondUsed, //钻石使用判断
  1189. RelicIntensify,
  1190. /// <summary>
  1191. /// 经验转换
  1192. /// </summary>
  1193. EXConvert
  1194. }
  1195. //判断鼠标是否点在ui上
  1196. public bool IsPointerOverGameObject(Vector2 mousePosition)
  1197. {
  1198. PointerEventData eventData = new PointerEventData(EventSystem.current);
  1199. eventData.position = mousePosition;
  1200. List<RaycastResult> raycastResults = new List<RaycastResult>();
  1201. //发射射线判断是否点到ui
  1202. EventSystem.current.RaycastAll(eventData, raycastResults);
  1203. if (raycastResults.Count > 0)
  1204. {
  1205. return true;
  1206. }
  1207. else
  1208. {
  1209. return false;
  1210. }
  1211. }
  1212. }
  1213. }