hch
2025-09-02 c8188ff3f37042491235a5034535d9bff2751ab4
Main/Component/UI/Core/OutlineEx.cs
@@ -186,13 +186,78 @@
            var uvMin = _Min(v1.uv0, v2.uv0, v3.uv0);
            var uvMax = _Max(v1.uv0, v2.uv0, v3.uv0);
            var uvOrigin = new Vector4(uvMin.x, uvMin.y, uvMax.x, uvMax.y);
            // 为每个顶点设置新的Position和UV,并传入原始UV框
            //
            v1 = _SetNewPosAndUV(v1, this.OutlineWidth, posCenter, triX, triY, uvX, uvY, uvOrigin);
            v2 = _SetNewPosAndUV(v2, this.OutlineWidth, posCenter, triX, triY, uvX, uvY, uvOrigin);
            v3 = _SetNewPosAndUV(v3, this.OutlineWidth, posCenter, triX, triY, uvX, uvY, uvOrigin);
            // 获取 RectMask2D 的边界
            // 确保描边顶点扩展不会超出 RectMask2D 的边界
            var mask = GetComponentInParent<RectMask2D>();
            if (mask != null)
            {
                // 将局部坐标转换为屏幕坐标
                Transform uiTransform = this.transform;
                Vector3 worldPos1 = uiTransform.TransformPoint(v1.position);
                Vector3 worldPos2 = uiTransform.TransformPoint(v2.position);
                Vector3 worldPos3 = uiTransform.TransformPoint(v3.position);
                Vector2 screenPos1 = CameraManager.uiCamera.WorldToScreenPoint(worldPos1);
                Vector2 screenPos2 = CameraManager.uiCamera.WorldToScreenPoint(worldPos2);
                Vector2 screenPos3 = CameraManager.uiCamera.WorldToScreenPoint(worldPos3);
                // 确保描边顶点扩展不会超出 RectMask2D 的边界
                var clipRect = mask.canvasRect;
                //clipRect是中心点为坐标0,0,转成屏幕的
                var maskMinX = Screen.width / 2 + clipRect.xMin;
                var maskMaxX = Screen.width / 2 + clipRect.xMax;
                var maskMinY = Screen.height / 2 + clipRect.yMin;
                var maskMaxY = Screen.height / 2 + clipRect.yMax;
                // //screenPos1 超出clipRect范围不显示
                bool isout = false;
                if (screenPos3.x < maskMinX || screenPos3.x > maskMaxX || screenPos3.y < maskMinY || screenPos3.y > maskMaxY)
                {
                    isout = true;
                }
                else if (screenPos2.x < maskMinX || screenPos2.x > maskMaxX || screenPos2.y < maskMinY || screenPos2.y > maskMaxY)
                {
                    isout = true;
                }
                else if (screenPos1.x < maskMinX || screenPos1.x > maskMaxX || screenPos1.y < maskMinY || screenPos1.y > maskMaxY)
                {
                    isout = true;
                }
                if (isout)
                {
                    v1.position = new Vector3(10000, 10000, 10000);
                    v2.position = new Vector3(10000, 10000, 10000);
                    v3.position = new Vector3(10000, 10000, 10000);
                }
                // screenPos1.x = Mathf.Clamp(screenPos1.x, maskMinX, maskMaxX);
                // screenPos1.y = Mathf.Clamp(screenPos1.y, maskMinY, maskMaxY);
                // screenPos2.x = Mathf.Clamp(screenPos2.x, maskMinX, maskMaxX);
                // screenPos2.y = Mathf.Clamp(screenPos2.y, maskMinY, maskMaxY);
                // screenPos3.x = Mathf.Clamp(screenPos3.x, maskMinX, maskMaxX);
                // screenPos3.y = Mathf.Clamp(screenPos3.y, maskMinY, maskMaxY);
                // // 将屏幕坐标转换为局部坐标
                // RectTransformUtility.ScreenPointToLocalPointInRectangle(uiTransform.GetComponent<RectTransform>(), screenPos1, CameraManager.uiCamera, out Vector2 localPos1);
                // RectTransformUtility.ScreenPointToLocalPointInRectangle(uiTransform.GetComponent<RectTransform>(), screenPos2, CameraManager.uiCamera, out Vector2 localPos2);
                // RectTransformUtility.ScreenPointToLocalPointInRectangle(uiTransform.GetComponent<RectTransform>(), screenPos3, CameraManager.uiCamera, out Vector2 localPos3);
                // v1.position = localPos1;
                // v2.position = localPos2;
                // v3.position = localPos3;
            }
            // 应用设置后的UIVertex
            //
            m_VetexList[i] = v1;
            m_VetexList[i + 1] = v2;
            m_VetexList[i + 2] = v3;