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.

79 lines
2.4 KiB

  1. using UnityEngine;
  2. using UnityEngine.PostProcessing;
  3. using System;
  4. using System.Linq.Expressions;
  5. namespace UnityEditor.PostProcessing
  6. {
  7. public class PostProcessingModelEditor
  8. {
  9. public PostProcessingModel target { get; internal set; }
  10. public SerializedProperty serializedProperty { get; internal set; }
  11. protected SerializedProperty m_SettingsProperty;
  12. protected SerializedProperty m_EnabledProperty;
  13. internal bool alwaysEnabled = false;
  14. internal PostProcessingProfile profile;
  15. internal PostProcessingInspector inspector;
  16. internal void OnPreEnable()
  17. {
  18. m_SettingsProperty = serializedProperty.FindPropertyRelative("m_Settings");
  19. m_EnabledProperty = serializedProperty.FindPropertyRelative("m_Enabled");
  20. OnEnable();
  21. }
  22. public virtual void OnEnable()
  23. {}
  24. public virtual void OnDisable()
  25. {}
  26. internal void OnGUI()
  27. {
  28. GUILayout.Space(5);
  29. var display = alwaysEnabled
  30. ? EditorGUIHelper.Header(serializedProperty.displayName, m_SettingsProperty, Reset)
  31. : EditorGUIHelper.Header(serializedProperty.displayName, m_SettingsProperty, m_EnabledProperty, Reset);
  32. if (display)
  33. {
  34. EditorGUI.indentLevel++;
  35. using (new EditorGUI.DisabledGroupScope(!m_EnabledProperty.boolValue))
  36. {
  37. OnInspectorGUI();
  38. }
  39. EditorGUI.indentLevel--;
  40. }
  41. }
  42. void Reset()
  43. {
  44. var obj = serializedProperty.serializedObject;
  45. Undo.RecordObject(obj.targetObject, "Reset");
  46. target.Reset();
  47. EditorUtility.SetDirty(obj.targetObject);
  48. }
  49. public virtual void OnInspectorGUI()
  50. {}
  51. public void Repaint()
  52. {
  53. inspector.Repaint();
  54. }
  55. protected SerializedProperty FindSetting<T, TValue>(Expression<Func<T, TValue>> expr)
  56. {
  57. return m_SettingsProperty.FindPropertyRelative(ReflectionUtils.GetFieldPath(expr));
  58. }
  59. protected SerializedProperty FindSetting<T, TValue>(SerializedProperty prop, Expression<Func<T, TValue>> expr)
  60. {
  61. return prop.FindPropertyRelative(ReflectionUtils.GetFieldPath(expr));
  62. }
  63. }
  64. }