ViewGlobal.cs 3.9 KB

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