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.

36 lines
1.1 KiB

  1. using UnityEngine;
  2. using UnityEngine.PostProcessing;
  3. namespace UnityEditor.PostProcessing
  4. {
  5. [CustomPropertyDrawer(typeof(GetSetAttribute))]
  6. sealed class GetSetDrawer : PropertyDrawer
  7. {
  8. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  9. {
  10. var attribute = (GetSetAttribute)base.attribute;
  11. EditorGUI.BeginChangeCheck();
  12. EditorGUI.PropertyField(position, property, label);
  13. if (EditorGUI.EndChangeCheck())
  14. {
  15. attribute.dirty = true;
  16. }
  17. else if (attribute.dirty)
  18. {
  19. var parent = ReflectionUtils.GetParentObject(property.propertyPath, property.serializedObject.targetObject);
  20. var type = parent.GetType();
  21. var info = type.GetProperty(attribute.name);
  22. if (info == null)
  23. Debug.LogError("Invalid property name \"" + attribute.name + "\"");
  24. else
  25. info.SetValue(parent, fieldInfo.GetValue(parent), null);
  26. attribute.dirty = false;
  27. }
  28. }
  29. }
  30. }