Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

FilmGrainEditor.cs 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using UnityEngine;
  2. using UnityEngine.Rendering.Universal;
  3. namespace UnityEditor.Rendering.Universal
  4. {
  5. [CustomEditor(typeof(FilmGrain))]
  6. sealed class FilmGrainEditor : VolumeComponentEditor
  7. {
  8. SerializedDataParameter m_Type;
  9. SerializedDataParameter m_Intensity;
  10. SerializedDataParameter m_Response;
  11. SerializedDataParameter m_Texture;
  12. public override void OnEnable()
  13. {
  14. var o = new PropertyFetcher<FilmGrain>(serializedObject);
  15. m_Type = Unpack(o.Find(x => x.type));
  16. m_Intensity = Unpack(o.Find(x => x.intensity));
  17. m_Response = Unpack(o.Find(x => x.response));
  18. m_Texture = Unpack(o.Find(x => x.texture));
  19. }
  20. public override void OnInspectorGUI()
  21. {
  22. PropertyField(m_Type);
  23. if (m_Type.value.intValue == (int)FilmGrainLookup.Custom)
  24. {
  25. using (new IndentLevelScope())
  26. PropertyField(m_Texture);
  27. var texture = (target as FilmGrain).texture.value;
  28. if (texture != null)
  29. {
  30. var importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter;
  31. // Fails when using an internal texture as you can't change import settings on
  32. // builtin resources, thus the check for null
  33. if (importer != null)
  34. {
  35. bool valid = importer.mipmapEnabled == false
  36. && importer.alphaSource == TextureImporterAlphaSource.FromGrayScale
  37. && importer.filterMode == FilterMode.Point
  38. && importer.textureCompression == TextureImporterCompression.Uncompressed
  39. && importer.textureType == TextureImporterType.SingleChannel;
  40. if (!valid)
  41. CoreEditorUtils.DrawFixMeBox("Invalid texture import settings.", () => SetTextureImportSettings(importer));
  42. }
  43. }
  44. }
  45. PropertyField(m_Intensity);
  46. PropertyField(m_Response);
  47. }
  48. static void SetTextureImportSettings(TextureImporter importer)
  49. {
  50. importer.textureType = TextureImporterType.SingleChannel;
  51. importer.alphaSource = TextureImporterAlphaSource.FromGrayScale;
  52. importer.mipmapEnabled = false;
  53. importer.filterMode = FilterMode.Point;
  54. importer.textureCompression = TextureImporterCompression.Uncompressed;
  55. importer.SaveAndReimport();
  56. AssetDatabase.Refresh();
  57. }
  58. }
  59. }