ViewGlobal.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using FairyGUI;
  2. using System.Collections.Generic;
  3. using UI.Common;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class ViewGlobal
  8. {
  9. private static UI_ComHolder comHolder;
  10. private static EffectUI _effectUI1;
  11. public static void CreatClickEffect()
  12. {
  13. if (comHolder == null)
  14. {
  15. comHolder = UI_ComHolder.Create();
  16. comHolder.target.touchable = false;
  17. ViewManager.AddChildToFloatLayer(comHolder.target);
  18. comHolder.target.SetPosition(-100, -100, 0);
  19. _effectUI1 = EffectUIPool.CreateEffectUI(comHolder.m_holder, "ui_dj", "DJ");
  20. GRoot.inst.onTouchBegin.Add(SetClickPos);
  21. }
  22. }
  23. private static void SetClickPos()
  24. {
  25. Vector2 pos = GRoot.inst.GlobalToLocal(Stage.inst.touchPosition);
  26. comHolder.m_holder.visible = false;
  27. comHolder.m_holder.visible = true;
  28. comHolder.target.SetPosition(pos.x, pos.y, 0);
  29. }
  30. /// <summary>
  31. /// 获取顶部摄像头的高度,减去一定的位移是因为设计图本身为顶部留出了一定的间隙
  32. /// </summary>
  33. /// <returns></returns>
  34. static float GetTopOffset()
  35. {
  36. //int designOffset = ((Screen.safeArea.height + Screen.safeArea.y) == Screen.height ? 0 : 80);
  37. int designOffset = 0;
  38. Debug.Log(Screen.height - Screen.safeArea.height - Screen.safeArea.y);
  39. return Screen.height - Screen.safeArea.height - Screen.safeArea.y - designOffset;
  40. }
  41. /// <summary>
  42. /// 获取画布根据分辨率适配后的,顶部的实际高度
  43. /// </summary>
  44. /// <returns></returns>
  45. public static float GetRealTopOffset()
  46. {
  47. return Screen.height / UIContentScaler.scaleFactor - GetUIHeight();
  48. }
  49. /// <summary>
  50. /// 获取画布根据分辨率适配后的UI高度
  51. /// </summary>
  52. /// <returns></returns>
  53. public static float GetUIHeight()
  54. {
  55. return (Screen.height - GetTopOffset()) / UIContentScaler.scaleFactor;
  56. }
  57. public static List<Transform> FindAllGLoaderInTrans(Transform parent)
  58. {
  59. List<Transform> foundChildren = new List<Transform>();
  60. // 遍历当前父节点的所有子节点
  61. foreach (Transform child in parent)
  62. {
  63. // 检查子节点的名称是否匹配
  64. if (child.name == "GLoader" || child.name == "Shape")
  65. {
  66. // 将匹配的子节点添加到列表中
  67. foundChildren.Add(child);
  68. }
  69. // 递归调用,查找孙子节点
  70. foundChildren.AddRange(FindAllGLoaderInTrans(child));
  71. }
  72. return foundChildren;
  73. }
  74. private static List<string> fullScreenPicNames = new List<string>() { "loaBg", "mask" };
  75. private static List<string> notMoveUI = new List<string>() { "Top_img" };
  76. public static bool IsFullScreenPic(string name)
  77. {
  78. foreach (string s in fullScreenPicNames)
  79. {
  80. if (name == s)
  81. return true;
  82. }
  83. return false;
  84. }
  85. public static bool IsNotMoveUI(string name)
  86. {
  87. foreach (string s in notMoveUI)
  88. {
  89. if (s.Contains(name))
  90. return true;
  91. }
  92. return false;
  93. }
  94. }
  95. }