ShaderLibrary.cs 744 B

123456789101112131415161718192021222324252627
  1. /// Credit SimonDarksideJ
  2. using System.Collections.Generic;
  3. namespace UnityEngine.UI.Extensions
  4. {
  5. public static class ShaderLibrary
  6. {
  7. public static Dictionary<string, Shader> shaderInstances = new Dictionary<string, Shader>();
  8. public static Shader[] preLoadedShaders;
  9. public static Shader GetShaderInstance(string shaderName)
  10. {
  11. if (shaderInstances.ContainsKey(shaderName))
  12. {
  13. return shaderInstances[shaderName];
  14. }
  15. var newInstance = Shader.Find(shaderName);
  16. if (newInstance != null)
  17. {
  18. shaderInstances.Add(shaderName, newInstance);
  19. }
  20. return newInstance;
  21. }
  22. }
  23. }