ui基本完毕,修了一大把的bug

This commit is contained in:
2026-07-13 02:28:39 +08:00
parent 1e20d73e90
commit fd22501f71
958 changed files with 378289 additions and 41038 deletions
@@ -12,6 +12,9 @@ public class GfxController : MonoBehaviour
{
public static GfxController Instance { get; private set; }
// 复用的属性块:命中特效透明度覆写用,避免每次命中访问 r.materials 克隆材质。
private MaterialPropertyBlock _fxPropertyBlock;
[Header("Combatant Objects")]
public GameObject enemyMoveObject;
public GameObject ally01MoveObject;
@@ -688,23 +691,28 @@ public class GfxController : MonoBehaviour
// 设置排序层级
r.sortingOrder = sortingOrder;
// 处理材质透明度
// 处理材质透明度:用 MaterialPropertyBlock 覆写 alpha,避免访问 r.materials
// 触发材质实例化(每次命中都会克隆并泄漏材质,产生 GC)。视觉结果等价。
if (transparency < 1f)
{
foreach (var mat in r.materials)
var sharedMat = r.sharedMaterial;
if (sharedMat != null)
{
if (mat.HasProperty("_Color"))
if (_fxPropertyBlock == null) _fxPropertyBlock = new MaterialPropertyBlock();
r.GetPropertyBlock(_fxPropertyBlock);
if (sharedMat.HasProperty("_Color"))
{
Color c = mat.color;
Color c = sharedMat.color;
c.a *= transparency;
mat.color = c;
_fxPropertyBlock.SetColor("_Color", c);
}
else if (mat.HasProperty("_BaseColor")) // URP 命名
else if (sharedMat.HasProperty("_BaseColor")) // URP 命名
{
Color c = mat.GetColor("_BaseColor");
Color c = sharedMat.GetColor("_BaseColor");
c.a *= transparency;
mat.SetColor("_BaseColor", c);
_fxPropertyBlock.SetColor("_BaseColor", c);
}
r.SetPropertyBlock(_fxPropertyBlock);
}
}
}