From 28cd278da1d35b1a8a43acabdd61aab23baffc79 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期二, 07 四月 2026 22:46:48 +0800
Subject: [PATCH] 0312 优化文字包边第一次打开界面可能变粗的问题

---
 Main/Component/UI/Core/OutlineEx.cs |   70 ++++++++++++++++++++++++++++-------
 1 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/Main/Component/UI/Core/OutlineEx.cs b/Main/Component/UI/Core/OutlineEx.cs
index e37e4b9..74cfdcf 100644
--- a/Main/Component/UI/Core/OutlineEx.cs
+++ b/Main/Component/UI/Core/OutlineEx.cs
@@ -39,7 +39,7 @@
     //榛樿10锛屼笉鍚岀殑棰滆壊锛堝寘鎷皟鏁碼lpha锛夎瑙変笂鎻忚竟绮楃粏鏈夊樊寮傦紝鏁卻hader閲屼箻浠�0.2閫傚簲涓嶅悓鎯呭喌
     public int OutlineWidth = 10;    
 
-    private static List<UIVertex> m_VetexList = new List<UIVertex>();
+    private List<UIVertex> m_VetexList = new List<UIVertex>();
 
     protected override void Start()
     {
@@ -49,8 +49,6 @@
         {
             if (base.graphic.material == null || base.graphic.material.shader.name != "TSF Shaders/UI/OutlineEx")
             {
-// #if UNITY_EDITOR
-
                 var texMaterial = ResManager.Instance.LoadAsset<Material>("Materials", "OutlineMat");
                 if (texMaterial != null)
                 {
@@ -60,10 +58,6 @@
                 {
                     Debug.LogError("娌℃湁鎵惧埌鏉愯川OutlineMat.mat");
                 }
-// #else
-//                 var shader = Shader.Find("TSF Shaders/UI/OutlineEx");
-//                 base.graphic.material = new Material(shader);
-// #endif
             }
 
             if (base.graphic.canvas)
@@ -95,7 +89,53 @@
                     base.graphic.canvas.additionalShaderChannels |= v2;
                 }
             }
+            
             this._Refresh();
+            
+            // 娉ㄥ唽瀛椾綋绾圭悊閲嶅缓浜嬩欢锛堝姩鎬佸瓧浣撻娆℃覆鏌撴椂鍙兘鏈氨缁級
+            if (base.graphic is Text textComponent && textComponent.font != null)
+            {
+                Font.textureRebuilt += OnFontTextureRebuilt;
+            }
+        }
+    }
+    
+    private void OnFontTextureRebuilt(Font font)
+    {
+        if (base.graphic is Text textComponent && textComponent.font == font)
+        {
+            // 鍦ㄥ瓧浣撻噸寤哄洖璋冧腑涓嶈兘鐩存帴璋冪敤SetVerticesDirty锛岄渶瑕佸欢杩�
+            if (gameObject.activeInHierarchy)
+            {
+                StartCoroutine(DelayRefresh());
+            }
+        }
+    }
+    
+    private System.Collections.IEnumerator DelayRefresh()
+    {
+        yield return null;
+        this._Refresh();
+    }
+    
+    protected override void OnDestroy()
+    {
+        base.OnDestroy();
+        Font.textureRebuilt -= OnFontTextureRebuilt;
+    }
+    
+    protected override void OnDisable()
+    {
+        base.OnDisable();
+        Font.textureRebuilt -= OnFontTextureRebuilt;
+    }
+    
+    protected override void OnEnable()
+    {
+        base.OnEnable();
+        if (base.graphic is Text textComponent && textComponent.font != null)
+        {
+            Font.textureRebuilt += OnFontTextureRebuilt;
         }
     }
     
@@ -128,11 +168,6 @@
 
     private void _Refresh()
     {
-        /*if (base.graphic.material.GetInt("_OutlineWidth") != this.OutlineWidth || base.graphic.material.GetColor("_OutlineColor") != this.OutlineColor)
-        {
-            base.graphic.material.SetColor("_OutlineColor", this.OutlineColor);
-            base.graphic.material.SetInt("_OutlineWidth", this.OutlineWidth);
-        }*/
         base.graphic.SetVerticesDirty();
     }
 
@@ -232,8 +267,15 @@
         var uv = pVertex.uv0;
 
 
-    uv += new Vector4((pUVX / pTriangleX.magnitude * posXOffset * (Vector2.Dot(pTriangleX, Vector2.right) > 0 ? 1 : -1)).x, (pUVX / pTriangleX.magnitude * posXOffset * (Vector2.Dot(pTriangleX, Vector2.right) > 0 ? 1 : -1)).y, 0, 0);
-    uv += new Vector4((pUVY / pTriangleY.magnitude * posYOffset * (Vector2.Dot(pTriangleY, Vector2.up) > 0 ? 1 : -1)).x, (pUVY / pTriangleY.magnitude * posYOffset * (Vector2.Dot(pTriangleY, Vector2.up) > 0 ? 1 : -1)).y, 0, 0);
+        // X鏂瑰悜UV鍋忕Щ
+        float xSign = Vector2.Dot(pTriangleX, Vector2.right) >= 0 ? 1f : -1f;
+        Vector2 uvOffsetX = (pUVX / pTriangleX.magnitude) * posXOffset * xSign;
+        
+        // Y鏂瑰悜UV鍋忕Щ - 浣跨敤鏇寸ǔ瀹氱殑鍒ゆ柇鏂瑰紡
+        float ySign = pTriangleY.y >= 0 ? 1f : -1f;
+        Vector2 uvOffsetY = (pUVY / pTriangleY.magnitude) * posYOffset * ySign;
+        
+        uv += new Vector4(uvOffsetX.x + uvOffsetY.x, uvOffsetX.y + uvOffsetY.y, 0, 0);
     
         pVertex.uv0 = uv;
 

--
Gitblit v1.8.0