mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-21 02:12:37 +08:00
65457e2636
This feature allow `UIEffect` component to automatically select shaders like 'UIEffect-SoftMaskable' without any manual configuration. close #270
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEditor.Build;
|
|
using UnityEditor.Rendering;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using PackageInfo = UnityEditor.PackageManager.PackageInfo;
|
|
|
|
namespace Coffee.UIEffects.Editors
|
|
{
|
|
internal class RemoveSoftMaskableVariantsIfNeeded : IPreprocessShaders
|
|
{
|
|
public int callbackOrder => 1;
|
|
|
|
// Remove the 'SOFTMASKABLE' variants if 'SoftMaskForUGUI' package is not installed.
|
|
public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data)
|
|
{
|
|
// If the shader is not for UIEffect: skip.
|
|
if (!shader.name.EndsWith(" (UIEffect)")) return;
|
|
|
|
// If the 'SoftMaskForUGUI' package is installed: skip.
|
|
if (PackageInfo.FindForAssetPath("Packages/com.coffee.softmask-for-ugui/package.json") != null) return;
|
|
|
|
// Remove the 'SOFTMASKABLE' variants.
|
|
var softMaskable = new ShaderKeyword(shader, "SOFTMASKABLE");
|
|
for (var i = data.Count - 1; i >= 0; i--)
|
|
{
|
|
var d = data[i];
|
|
if (d.shaderKeywordSet.IsEnabled(softMaskable))
|
|
{
|
|
data.RemoveAt(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|