41 lines
913 B
C#
41 lines
913 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UltimateWater.Internal
|
|
{
|
|
public class UtilityShaderVariants
|
|
{
|
|
private readonly Dictionary<int, Material> _Materials;
|
|
|
|
private static UtilityShaderVariants _Instance;
|
|
|
|
public static UtilityShaderVariants Instance
|
|
{
|
|
get
|
|
{
|
|
return (_Instance != null) ? _Instance : (_Instance = new UtilityShaderVariants());
|
|
}
|
|
}
|
|
|
|
private UtilityShaderVariants()
|
|
{
|
|
_Materials = new Dictionary<int, Material>();
|
|
}
|
|
|
|
public Material GetVariant(Shader shader, string keywords)
|
|
{
|
|
int key = shader.GetInstanceID() ^ keywords.GetHashCode();
|
|
Material value;
|
|
if (!_Materials.TryGetValue(key, out value))
|
|
{
|
|
Material material = new Material(shader);
|
|
material.hideFlags = HideFlags.DontSave;
|
|
material.shaderKeywords = keywords.Split(' ');
|
|
value = material;
|
|
_Materials[key] = value;
|
|
}
|
|
return value;
|
|
}
|
|
}
|
|
}
|