diff --git a/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs b/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs index 1a20dde..c43e091 100644 --- a/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs +++ b/Packages/src/Runtime/Internal/Utilities/ShaderVariantRegistry.cs @@ -61,7 +61,10 @@ public override int GetHashCode() public ShaderVariantCollection shaderVariantCollection => m_Asset; - public Shader FindOptionalShader(Shader shader, string format, string defaultOptionalShaderName) + public Shader FindOptionalShader(Shader shader, + string requiredName, + string format, + string defaultOptionalShaderName) { if (!shader) return null; @@ -72,6 +75,13 @@ public Shader FindOptionalShader(Shader shader, string format, string defaultOpt return Shader.Find(optionalShaderName); } + // Required shader. + if (shader.name.Contains(requiredName)) + { + _cachedOptionalShaders[id] = shader.name; + return shader; + } + // Find optional shader. Shader optionalShader; var shaderName = shader.name; @@ -116,7 +126,8 @@ public void InitializeIfNeeded(Object owner, string optionalName) { return File.ReadLines(x.path) .Take(10) - .Select(line => Regex.Match(line, @"//\s*OptionalShaderFor:\s*(.*)$")) + .Where(line => line.Contains($"OptionalShader@{optionalName}")) + .Select(line => Regex.Match(line, @":\s*(.*)$")) .Where(match => match.Success) .Select(match => new StringPair() { key = match.Groups[1].Value, value = x.name }); }) @@ -375,12 +386,12 @@ private static bool DrawRegisteredShaderVariants(bool expand, SerializedProperty return expand; } - private static void ShowShaderDropdown(SerializedProperty property, string option, bool included) + private static void ShowShaderDropdown(SerializedProperty property, string option, bool required) { var menu = new GenericMenu(); var current = property.stringValue; var allShaderNames = ShaderUtil.GetAllShaderInfo() - .Where(s => s.name.Contains(option) == included) + .Where(s => !required || s.name.Contains(option)) .Select(s => s.name); foreach (var shaderName in allShaderNames) diff --git a/Packages/src/Runtime/Utilities/SoftMaskUtils.cs b/Packages/src/Runtime/Utilities/SoftMaskUtils.cs index 208e69b..8b32676 100644 --- a/Packages/src/Runtime/Utilities/SoftMaskUtils.cs +++ b/Packages/src/Runtime/Utilities/SoftMaskUtils.cs @@ -191,7 +191,9 @@ public static Material CreateSoftMaskable( var mat = new Material(baseMat) { shader = UISoftMaskProjectSettings.shaderRegistry.FindOptionalShader(baseMat.shader, - "Hidden/{0} (SoftMaskable)", "Hidden/UI/Default (SoftMaskable)"), + "(SoftMaskable)", + "Hidden/{0} (SoftMaskable)", + "Hidden/UI/Default (SoftMaskable)"), hideFlags = HideFlags.HideAndDontSave }; Profiler.EndSample();