From 8d26a118bc6dded527cef85638d9151eb4c6b21f Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期五, 10 四月 2026 00:02:45 +0800
Subject: [PATCH] 0312 修复包边纹理绑定问题
---
Main/Component/UI/Core/OutlineEx.cs | 93 +++++++++++++++++-----------------------------
1 files changed, 34 insertions(+), 59 deletions(-)
diff --git a/Main/Component/UI/Core/OutlineEx.cs b/Main/Component/UI/Core/OutlineEx.cs
index 74cfdcf..54ec2ff 100644
--- a/Main/Component/UI/Core/OutlineEx.cs
+++ b/Main/Component/UI/Core/OutlineEx.cs
@@ -47,17 +47,43 @@
if (base.graphic)
{
- if (base.graphic.material == null || base.graphic.material.shader.name != "TSF Shaders/UI/OutlineEx")
+ // 鍏堣缃潗璐紙鏃犺鏄惁宸茶缃紝閮界‘淇濇纭級
+ var texMaterial = ResManager.Instance.LoadAsset<Material>("Materials", "OutlineMat");
+ if (texMaterial != null)
{
- var texMaterial = ResManager.Instance.LoadAsset<Material>("Materials", "OutlineMat");
- if (texMaterial != null)
+ // 鍒涘缓瀹炰緥鏉愯川锛岄伩鍏嶅叡浜潗璐ㄧ殑闂
+ var instanceMat = new Material(texMaterial);
+
+ // 鑾峰彇姝g‘鐨勭汗鐞嗗苟缁戝畾
+ Texture mainTexture = null;
+ if (base.graphic is Text text)
{
- base.graphic.material = texMaterial;
+ mainTexture = text.font.material.mainTexture;
+ }
+ else if (base.graphic is Image image && image.sprite != null)
+ {
+ mainTexture = image.sprite.texture;
+ }
+ else if (base.graphic is RawImage rawImage && rawImage.texture != null)
+ {
+ mainTexture = rawImage.texture;
}
else
{
- Debug.LogError("娌℃湁鎵惧埌鏉愯川OutlineMat.mat");
+ // 鍏滃簳锛氫娇鐢ㄥ綋鍓嶆潗璐ㄧ殑绾圭悊
+ mainTexture = instanceMat.GetTexture("_MainTex");
}
+
+ if (mainTexture != null)
+ {
+ instanceMat.SetTexture("_MainTex", mainTexture);
+ }
+
+ base.graphic.material = instanceMat;
+ }
+ else
+ {
+ Debug.LogError("娌℃湁鎵惧埌鏉愯川OutlineMat.mat");
}
if (base.graphic.canvas)
@@ -91,53 +117,10 @@
}
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;
- }
- }
#if UNITY_EDITOR
protected override void OnValidate()
@@ -266,16 +249,8 @@
// UV
var uv = pVertex.uv0;
-
- // 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);
+ 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);
pVertex.uv0 = uv;
--
Gitblit v1.8.0