Эх сурвалжийг харах

提交UI适配核心代码;修改服装合成的羽化范围;修改剧情对话的遮罩位置

leiyasi 1 жил өмнө
parent
commit
43e8b65c54

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Views/ClothingSynthetic/ClothingSyntheticView.cs

@@ -514,7 +514,7 @@ namespace GFGGame
             _ui.m_loaBg2.material = copyM;
             _ui.m_loaBg2.position = _ui.m_loaBg.position;
             float startY = _ui.m_loaBg2Pos.position.y;
-            float endY = _ui.m_posHelper.position.y;
+            float endY = _ui.m_posHelper.position.y + ViewGlobal.GetRealTopOffset();
             float rate = 1 - ((Mathf.Abs(startY - endY)) / _ui.m_loaBg2.height);
             _ui.m_loaBg2.material.SetFloat("_MinHeight", rate - 0.01f);
             _ui.m_loaBg2.material.SetFloat("_MaxHeight", rate - 0.03f);

+ 2 - 2
GameClient/Assets/Game/HotUpdate/Views/MainStory/StoryDialogView.cs

@@ -96,8 +96,8 @@ namespace GFGGame
             _ui.m_btnNext.height = GRoot.inst.height;
             _ui.m_mask1.height = (GRoot.inst.height - 1920) / 2;
             _ui.m_mask2.height = (GRoot.inst.height - 1920) / 2;
-            _ui.m_mask1.y = 0;
-            _ui.m_mask2.y = GRoot.inst.height - _ui.m_mask2.height;
+            _ui.m_mask1.y = -ViewGlobal.GetRealTopOffset();
+            _ui.m_mask2.y = GRoot.inst.height - _ui.m_mask2.height - ViewGlobal.GetRealTopOffset();
             _ui.m_btnNext.AddRelation(GRoot.inst, RelationType.Size);
             _ui.m_btnBack.onClick.Add(OnClickBtnBack);
             _ui.m_btnNext.onClick.Add(OnClickBtnNext);

+ 60 - 1
GameClient/Assets/Game/HotUpdate/Views/UIView.cs

@@ -1,6 +1,7 @@
 using ET;
 using FairyGUI;
 using System.Collections;
+using System.Collections.Generic;
 using UnityEngine;
 
 namespace GFGGame
@@ -228,10 +229,68 @@ namespace GFGGame
 
         private void MakeFullScreen(GObject ui)
         {
-            ui.MakeFullScreen();
+            MakeUIFullScreen(ui);
             ui.AddRelation(GRoot.inst, RelationType.Size);
         }
 
+        private bool _adaptFinished = false;
+        public void MakeUIFullScreen(GObject ui)
+        {
+            if (_adaptFinished)
+            {
+                return;
+            }
+
+            //这里做了最大宽度适配
+            float targetWidth;
+            float maxAspectRatio = 1080 * 1.0f / 1920;
+            if (Screen.width * 1.0f / Screen.height > maxAspectRatio)
+            {
+                targetWidth = GRoot.inst.height * maxAspectRatio;
+                ui.Center();
+            }
+            else
+            {
+                targetWidth = GRoot.inst.width;
+            }
+
+            float offsetY = ViewGlobal.GetRealTopOffset();
+
+            GameObject uiObj = viewCom.displayObject.gameObject;
+
+            // 处理全屏背景图
+            List<Transform> list = ViewGlobal.FindAllGLoaderInTrans(uiObj.transform);
+
+            for (int i = 0; i < list.Count; i++)
+            {
+                GameObject bg = list[i].gameObject;
+                DisplayObjectInfo bgInfo = bg.GetComponent<DisplayObjectInfo>();
+                GObject obj = GRoot.inst.DisplayObjectToGObject(bgInfo.displayObject);
+                
+                if (obj != null && ViewGlobal.IsFullScreenPic(obj.name) && obj.height >= 1920)
+                {
+                    switch (bg.name)
+                    {
+                        case "GLoader":
+                            break;
+                        case "Shape":
+                            break;
+                    }
+                    obj.AddRelation(ui, RelationType.Center_Center);
+                    obj.RemoveRelation(ui, RelationType.Size);
+                    obj.SetSize(1080, 2400);
+                    obj.SetXY(obj.x, obj.y - offsetY / 2);
+                }
+            }
+
+            // UI整体高度缩放
+            ui.SetSize(targetWidth, ViewGlobal.GetUIHeight());
+            // UI整体下移动
+            ui.SetXY(ui.x, offsetY);
+
+            _adaptFinished = true;
+        }
+
         void __addedToStage()
         {
             DoShowAnimation();

+ 59 - 0
GameClient/Assets/Game/HotUpdate/Views/ViewGlobal.cs

@@ -1,4 +1,5 @@
 using FairyGUI;
+using System.Collections.Generic;
 using UI.Common;
 using UnityEngine;
 
@@ -29,5 +30,63 @@ namespace GFGGame
             comHolder.m_holder.visible = true;
             comHolder.target.SetPosition(pos.x, pos.y, 0);
         }
+
+
+        /// <summary>
+        /// 获取顶部摄像头的高度,减去一定的位移是因为设计图本身为顶部留出了一定的间隙
+        /// </summary>
+        /// <returns></returns>
+        static float GetTopOffset()
+        {
+            int designOffset = (Screen.safeArea.height == Screen.height ? 0 : 50);
+            return Screen.height - Screen.safeArea.height - Screen.safeArea.y - designOffset;
+        }
+
+        public static float GetRealTopOffset()
+        {
+            return Screen.height / UIContentScaler.scaleFactor - GetUIHeight();
+        }
+
+        /// <summary>
+        /// 获取UI适配后的高度
+        /// </summary>
+        /// <returns></returns>
+        public static float GetUIHeight()
+        {
+            return (Screen.height - GetTopOffset()) / UIContentScaler.scaleFactor;
+        }
+
+        public static List<Transform> FindAllGLoaderInTrans(Transform parent)
+        {
+            List<Transform> foundChildren = new List<Transform>();
+
+            // 遍历当前父节点的所有子节点
+            foreach (Transform child in parent)
+            {
+                // 检查子节点的名称是否匹配
+                if (child.name == "GLoader" || child.name == "Shape")
+                {
+                    // 将匹配的子节点添加到列表中
+                    foundChildren.Add(child);
+                }
+
+                // 递归调用,查找孙子节点
+                foundChildren.AddRange(FindAllGLoaderInTrans(child));
+            }
+
+            return foundChildren;
+        }
+
+        private static List<string> fullScreenPicNames = new List<string>() { "loaBg", "mask" };
+
+        public static bool IsFullScreenPic(string name)
+        {
+            foreach(string s in fullScreenPicNames)
+            {
+                if(name == s)
+                    return true;
+            }
+            return false;
+        }
     }
 }