fix: fixed an issue where shader variants were not registered automatically

close #383
This commit is contained in:
mob-sakai
2025-12-18 17:27:32 +09:00
parent 4e30651290
commit 6b79864a39
@@ -270,7 +270,7 @@ namespace Coffee.UIEffectInternal
_sb.Length--; // Remove last space.
}
var hash = new Hash128((uint)shader.GetInstanceID(), (uint)_sb.GetHashCode(), 0, 0);
var hash = new Hash128((uint)shader.GetInstanceID(), (uint)GetContentsHash(_sb), 0, 0);
if (_cachedVariants.TryGetValue(hash, out var result))
{
Profiler.EndSample();
@@ -288,6 +288,17 @@ namespace Coffee.UIEffectInternal
Profiler.EndSample();
return (variant, pair);
}
private static int GetContentsHash(StringBuilder sb)
{
var hash = 17;
for (var i = 0; i < sb.Length; i++)
{
hash = unchecked(hash * 31 + sb[i]);
}
return hash;
}
#endif
}