UIManager.cs 47 KB

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