CheckMappers.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using TriLibCore.Mappers;
  2. using TriLibCore.Utils;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace TriLibCore.Editor
  6. {
  7. public static class CheckMappers
  8. {
  9. [InitializeOnEnterPlayMode]
  10. [InitializeOnLoadMethod]
  11. public static void Initialize()
  12. {
  13. var hasAnyMapper = false;
  14. for (var i = 0; i < MaterialMapper.RegisteredMappers.Count; i++)
  15. {
  16. var materialMapperName = MaterialMapper.RegisteredMappers[i];
  17. if (TriLibSettings.GetBool(materialMapperName))
  18. {
  19. hasAnyMapper = true;
  20. break;
  21. }
  22. }
  23. if (!hasAnyMapper)
  24. {
  25. string materialMapper;
  26. if (GraphicsSettingsUtils.IsUsingHDRPPipeline)
  27. {
  28. materialMapper = "HDRPMaterialMapper";
  29. }
  30. else if (GraphicsSettingsUtils.IsUsingUniversalPipeline)
  31. {
  32. materialMapper = "UniversalRPMaterialMapper";
  33. }
  34. else
  35. {
  36. materialMapper = "StandardMaterialMapper";
  37. }
  38. Debug.Log($"TriLib is configured to use the '{materialMapper}' Material Mapper. If you want to use different Material Mappers, you can change this setting on the Project Settings/TriLib area.");
  39. TriLibSettings.SetBool(materialMapper, true);
  40. }
  41. }
  42. [MenuItem("Tools/TriLib/Select Material Mappers based on Rendering Pipeline")]
  43. public static void AutoSelect()
  44. {
  45. for (var i = 0; i < MaterialMapper.RegisteredMappers.Count; i++)
  46. {
  47. var materialMapperName = MaterialMapper.RegisteredMappers[i];
  48. TriLibSettings.SetBool(materialMapperName, false);
  49. }
  50. string materialMapper;
  51. if (GraphicsSettingsUtils.IsUsingHDRPPipeline)
  52. {
  53. materialMapper = "HDRPMaterialMapper";
  54. }
  55. else if (GraphicsSettingsUtils.IsUsingUniversalPipeline)
  56. {
  57. materialMapper = "UniversalRPMaterialMapper";
  58. }
  59. else
  60. {
  61. materialMapper = "StandardMaterialMapper";
  62. }
  63. SelectMapper(materialMapper);
  64. }
  65. public static void SelectMapper(string materialMapper)
  66. {
  67. Debug.Log($"TriLib is configured to use the '{materialMapper}' Material Mapper. If you want to use different Material Mappers, you can change this setting on the Project Settings/TriLib area.");
  68. TriLibSettings.SetBool(materialMapper, true);
  69. }
  70. }
  71. }