ViewGlobal.cs 4.2 KB

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