材质修改

This commit is contained in:
tianmo committed 2026-10-12 14:26:05 +08:00
1 parent ae5c4212dc
commit b26c7bbebd
20 files changed
+7820 -89

No files matched your search

+35 -7
View File
@@ -50,20 +50,48 @@ public abstract class UIMaskEnumDrawer : MaterialPropertyDrawer
}
}
// 混合模式:加色 / 普通混合
// 数值对应 UnityEngine.Rendering.BlendMode:SrcAlpha=5, One=1, OneMinusSrcAlpha=10
// 混合模式:Additive / Alpha / Alpha Premultiplied / Opaque
// 数值对应 UnityEngine.Rendering.BlendMode:SrcAlpha=5, One=1, OneMinusSrcAlpha=10, Zero=0
// Opaque 会同时打开 ZWrite(不透明需要写深度),其余模式 ZWrite = 0
public class UIMaskBlendMode : UIMaskEnumDrawer
{
private static readonly string[] Items = { "Additive", "AlphaBlend" };
private static readonly string[] Items = { "Additive", "Alpha", "Alpha Premultiplied", "Opaque" };
protected override string[] Options => Items;
protected override void Apply(MaterialEditor editor, int index)
{
SetValue(editor, "_SrcBlend", (float)UnityEngine.Rendering.BlendMode.SrcAlpha);
SetValue(editor, "_DstBlend", index == 0
? (float)UnityEngine.Rendering.BlendMode.One
: (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
const float srcAlpha = (float)UnityEngine.Rendering.BlendMode.SrcAlpha; // 5
const float one = (float)UnityEngine.Rendering.BlendMode.One; // 1
const float oneMinusSrcAlpha = (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha; // 10
const float zero = (float)UnityEngine.Rendering.BlendMode.Zero; // 0
switch (index)
{
case 1: // Alpha:标准透明混合
SetValue(editor, "_SrcBlend", srcAlpha);
SetValue(editor, "_DstBlend", oneMinusSrcAlpha);
SetValue(editor, "_ZWrite", 0f);
break;
case 2: // Alpha Premultiplied:颜色已预乘 alpha,源因子用 One
SetValue(editor, "_SrcBlend", one);
SetValue(editor, "_DstBlend", oneMinusSrcAlpha);
SetValue(editor, "_ZWrite", 0f);
break;
case 3: // Opaque:不混合 + 写深度
SetValue(editor, "_SrcBlend", one);
SetValue(editor, "_DstBlend", zero);
SetValue(editor, "_ZWrite", 1f);
break;
default: // Additive:SrcAlpha + One
SetValue(editor, "_SrcBlend", srcAlpha);
SetValue(editor, "_DstBlend", one);
SetValue(editor, "_ZWrite", 0f);
break;
}
}
}