using System.Collections.Generic; using UnityEngine; namespace UltimateWater.Internal { public class UtilityShaderVariants { private readonly Dictionary _Materials; private static UtilityShaderVariants _Instance; public static UtilityShaderVariants Instance { get { return (_Instance != null) ? _Instance : (_Instance = new UtilityShaderVariants()); } } private UtilityShaderVariants() { _Materials = new Dictionary(); } 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; } } }