暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ChannelMixerEditor.cs 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using UnityEngine;
  2. using UnityEngine.Rendering.Universal;
  3. namespace UnityEditor.Rendering.Universal
  4. {
  5. [CustomEditor(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. int currentChannel = m_SelectedChannel.value;
  35. EditorGUI.BeginChangeCheck();
  36. {
  37. using (new EditorGUILayout.HorizontalScope())
  38. {
  39. if (GUILayout.Toggle(currentChannel == 0, EditorGUIUtility.TrTextContent("Red", "Red output channel."), EditorStyles.miniButtonLeft)) currentChannel = 0;
  40. if (GUILayout.Toggle(currentChannel == 1, EditorGUIUtility.TrTextContent("Green", "Green output channel."), EditorStyles.miniButtonMid)) currentChannel = 1;
  41. if (GUILayout.Toggle(currentChannel == 2, EditorGUIUtility.TrTextContent("Blue", "Blue output channel."), EditorStyles.miniButtonRight)) currentChannel = 2;
  42. }
  43. }
  44. if (EditorGUI.EndChangeCheck())
  45. GUI.FocusControl(null);
  46. m_SelectedChannel.value = currentChannel;
  47. if (currentChannel == 0)
  48. {
  49. PropertyField(m_RedOutRedIn, EditorGUIUtility.TrTextContent("Red"));
  50. PropertyField(m_RedOutGreenIn, EditorGUIUtility.TrTextContent("Green"));
  51. PropertyField(m_RedOutBlueIn, EditorGUIUtility.TrTextContent("Blue"));
  52. }
  53. else if (currentChannel == 1)
  54. {
  55. PropertyField(m_GreenOutRedIn, EditorGUIUtility.TrTextContent("Red"));
  56. PropertyField(m_GreenOutGreenIn, EditorGUIUtility.TrTextContent("Green"));
  57. PropertyField(m_GreenOutBlueIn, EditorGUIUtility.TrTextContent("Blue"));
  58. }
  59. else
  60. {
  61. PropertyField(m_BlueOutRedIn, EditorGUIUtility.TrTextContent("Red"));
  62. PropertyField(m_BlueOutGreenIn, EditorGUIUtility.TrTextContent("Green"));
  63. PropertyField(m_BlueOutBlueIn, EditorGUIUtility.TrTextContent("Blue"));
  64. }
  65. }
  66. }
  67. }