ShaderUtils.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Linq;
  3. using UnityEngine.Scripting.APIUpdating;
  4. namespace UnityEngine.Rendering.Universal
  5. {
  6. [MovedFrom("UnityEngine.Rendering.LWRP")] public enum ShaderPathID
  7. {
  8. Lit,
  9. SimpleLit,
  10. Unlit,
  11. TerrainLit,
  12. ParticlesLit,
  13. ParticlesSimpleLit,
  14. ParticlesUnlit,
  15. BakedLit,
  16. Count
  17. }
  18. [MovedFrom("UnityEngine.Rendering.LWRP")] public static class ShaderUtils
  19. {
  20. static readonly string[] s_ShaderPaths =
  21. {
  22. "Universal Render Pipeline/Lit",
  23. "Universal Render Pipeline/Simple Lit",
  24. "Universal Render Pipeline/Unlit",
  25. "Universal Render Pipeline/Terrain/Lit",
  26. "Universal Render Pipeline/Particles/Lit",
  27. "Universal Render Pipeline/Particles/Simple Lit",
  28. "Universal Render Pipeline/Particles/Unlit",
  29. "Universal Render Pipeline/Baked Lit",
  30. };
  31. public static string GetShaderPath(ShaderPathID id)
  32. {
  33. int index = (int)id;
  34. if (index < 0 && index >= (int)ShaderPathID.Count)
  35. {
  36. Debug.LogError("Trying to access universal shader path out of bounds");
  37. return "";
  38. }
  39. return s_ShaderPaths[index];
  40. }
  41. public static ShaderPathID GetEnumFromPath(string path)
  42. {
  43. var index = Array.FindIndex(s_ShaderPaths, m => m == path);
  44. return (ShaderPathID)index;
  45. }
  46. public static bool IsLWShader(Shader shader)
  47. {
  48. return s_ShaderPaths.Contains(shader.name);
  49. }
  50. }
  51. }