You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.2 KiB

  1. using UnityEngine;
  2. using UnityEngine.PostProcessing;
  3. namespace UnityEditor.PostProcessing
  4. {
  5. using Settings = UserLutModel.Settings;
  6. [PostProcessingModelEditor(typeof(UserLutModel))]
  7. public class UserLutModelEditor : PostProcessingModelEditor
  8. {
  9. SerializedProperty m_Texture;
  10. SerializedProperty m_Contribution;
  11. public override void OnEnable()
  12. {
  13. m_Texture = FindSetting((Settings x) => x.lut);
  14. m_Contribution = FindSetting((Settings x) => x.contribution);
  15. }
  16. public override void OnInspectorGUI()
  17. {
  18. var lut = (target as UserLutModel).settings.lut;
  19. // Checks import settings on the lut, offers to fix them if invalid
  20. if (lut != null)
  21. {
  22. var importer = (TextureImporter)AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(lut));
  23. if (importer != null) // Fails when using an internal texture
  24. {
  25. #if UNITY_5_5_OR_NEWER
  26. bool valid = importer.anisoLevel == 0
  27. && importer.mipmapEnabled == false
  28. && importer.sRGBTexture == false
  29. && (importer.textureCompression == TextureImporterCompression.Uncompressed);
  30. #else
  31. bool valid = importer.anisoLevel == 0
  32. && importer.mipmapEnabled == false
  33. && importer.linearTexture == true
  34. && (importer.textureFormat == TextureImporterFormat.RGB24 || importer.textureFormat == TextureImporterFormat.AutomaticTruecolor);
  35. #endif
  36. if (!valid)
  37. {
  38. EditorGUILayout.HelpBox("Invalid LUT import settings.", MessageType.Warning);
  39. GUILayout.Space(-32);
  40. using (new EditorGUILayout.HorizontalScope())
  41. {
  42. GUILayout.FlexibleSpace();
  43. if (GUILayout.Button("Fix", GUILayout.Width(60)))
  44. {
  45. SetLUTImportSettings(importer);
  46. AssetDatabase.Refresh();
  47. }
  48. GUILayout.Space(8);
  49. }
  50. GUILayout.Space(11);
  51. }
  52. }
  53. else
  54. {
  55. m_Texture.objectReferenceValue = null;
  56. }
  57. }
  58. EditorGUILayout.PropertyField(m_Texture);
  59. EditorGUILayout.PropertyField(m_Contribution);
  60. }
  61. void SetLUTImportSettings(TextureImporter importer)
  62. {
  63. #if UNITY_5_5_OR_NEWER
  64. importer.textureType = TextureImporterType.Default;
  65. importer.sRGBTexture = false;
  66. importer.textureCompression = TextureImporterCompression.Uncompressed;
  67. #else
  68. importer.textureType = TextureImporterType.Advanced;
  69. importer.linearTexture = true;
  70. importer.textureFormat = TextureImporterFormat.RGB24;
  71. #endif
  72. importer.anisoLevel = 0;
  73. importer.mipmapEnabled = false;
  74. importer.SaveAndReimport();
  75. }
  76. }
  77. }