UIManager.cs 47 KB

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