TargetedPropertyDrawer.cs 840 B

12345678910111213141516171819202122232425262728
  1. using System.Reflection;
  2. namespace UnityEditor.Recorder
  3. {
  4. class TargetedPropertyDrawer<T> : PropertyDrawer where T : class
  5. {
  6. protected T target;
  7. protected virtual void Initialize(SerializedProperty prop)
  8. {
  9. if (target == null)
  10. {
  11. var path = prop.propertyPath.Split('.');
  12. object obj = prop.serializedObject.targetObject;
  13. foreach (var pathNode in path)
  14. obj = GetSerializedField(obj, pathNode).GetValue(obj);
  15. target = obj as T;
  16. }
  17. }
  18. static FieldInfo GetSerializedField(object target, string pathNode)
  19. {
  20. return target.GetType().GetField(pathNode, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
  21. }
  22. }
  23. }