ChannelMixerEditor.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using UnityEngine;
  2. using UnityEngine.Rendering.Universal;
  3. namespace UnityEditor.Rendering.Universal
  4. {
  5. [VolumeComponentEditor(typeof(ChannelMixer))]
  6. sealed class ChannelMixerEditor : VolumeComponentEditor
  7. {
  8. SerializedDataParameter m_RedOutRedIn;
  9. SerializedDataParameter m_RedOutGreenIn;
  10. SerializedDataParameter m_RedOutBlueIn;
  11. SerializedDataParameter m_GreenOutRedIn;
  12. SerializedDataParameter m_GreenOutGreenIn;
  13. SerializedDataParameter m_GreenOutBlueIn;
  14. SerializedDataParameter m_BlueOutRedIn;
  15. SerializedDataParameter m_BlueOutGreenIn;
  16. SerializedDataParameter m_BlueOutBlueIn;
  17. SavedInt m_SelectedChannel;
  18. public override void OnEnable()
  19. {
  20. var o = new PropertyFetcher<ChannelMixer>(serializedObject);
  21. m_RedOutRedIn = Unpack(o.Find(x => x.redOutRedIn));
  22. m_RedOutGreenIn = Unpack(o.Find(x => x.redOutGreenIn));
  23. m_RedOutBlueIn = Unpack(o.Find(x => x.redOutBlueIn));
  24. m_GreenOutRedIn = Unpack(o.Find(x => x.greenOutRedIn));
  25. m_GreenOutGreenIn = Unpack(o.Find(x => x.greenOutGreenIn));
  26. m_GreenOutBlueIn = Unpack(o.Find(x => x.greenOutBlueIn));
  27. m_BlueOutRedIn = Unpack(o.Find(x => x.blueOutRedIn));
  28. m_BlueOutGreenIn = Unpack(o.Find(x => x.blueOutGreenIn));
  29. m_BlueOutBlueIn = Unpack(o.Find(x => x.blueOutBlueIn));
  30. m_SelectedChannel = new SavedInt($"{target.GetType()}.SelectedChannel", 0);
  31. }
  32. public override void OnInspectorGUI()
  33. {
  34. if (UniversalRenderPipeline.asset?.postProcessingFeatureSet == PostProcessingFeatureSet.PostProcessingV2)
  35. {
  36. EditorGUILayout.HelpBox(UniversalRenderPipelineAssetEditor.Styles.postProcessingGlobalWarning, MessageType.Warning);
  37. return;
  38. }
  39. int currentChannel = m_SelectedChannel.value;
  40. EditorGUI.BeginChangeCheck();
  41. {
  42. using (new EditorGUILayout.HorizontalScope())
  43. {
  44. if (GUILayout.Toggle(currentChannel == 0, EditorGUIUtility.TrTextContent("Red", "Red output channel."), EditorStyles.miniButtonLeft)) currentChannel = 0;
  45. if (GUILayout.Toggle(currentChannel == 1, EditorGUIUtility.TrTextContent("Green", "Green output channel."), EditorStyles.miniButtonMid)) currentChannel = 1;
  46. if (GUILayout.Toggle(currentChannel == 2, EditorGUIUtility.TrTextContent("Blue", "Blue output channel."), EditorStyles.miniButtonRight)) currentChannel = 2;
  47. }
  48. }
  49. if (EditorGUI.EndChangeCheck())
  50. GUI.FocusControl(null);
  51. m_SelectedChannel.value = currentChannel;
  52. if (currentChannel == 0)
  53. {
  54. PropertyField(m_RedOutRedIn, EditorGUIUtility.TrTextContent("Red"));
  55. PropertyField(m_RedOutGreenIn, EditorGUIUtility.TrTextContent("Green"));
  56. PropertyField(m_RedOutBlueIn, EditorGUIUtility.TrTextContent("Blue"));
  57. }
  58. else if (currentChannel == 1)
  59. {
  60. PropertyField(m_GreenOutRedIn, EditorGUIUtility.TrTextContent("Red"));
  61. PropertyField(m_GreenOutGreenIn, EditorGUIUtility.TrTextContent("Green"));
  62. PropertyField(m_GreenOutBlueIn, EditorGUIUtility.TrTextContent("Blue"));
  63. }
  64. else
  65. {
  66. PropertyField(m_BlueOutRedIn, EditorGUIUtility.TrTextContent("Red"));
  67. PropertyField(m_BlueOutGreenIn, EditorGUIUtility.TrTextContent("Green"));
  68. PropertyField(m_BlueOutBlueIn, EditorGUIUtility.TrTextContent("Blue"));
  69. }
  70. }
  71. }
  72. }