SignalEventDrawer.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using JetBrains.Annotations;
  3. using UnityEditorInternal;
  4. using UnityEngine;
  5. using UnityEngine.Timeline;
  6. namespace UnityEditor.Timeline.Signals
  7. {
  8. [CustomPropertyDrawer(typeof(CustomSignalEventDrawer))]
  9. [UsedImplicitly]
  10. class SignalEventDrawer : UnityEventDrawer
  11. {
  12. static GameObject FindBoundObject(SerializedProperty property)
  13. {
  14. var component = property.serializedObject.targetObject as Component;
  15. return component != null ? component.gameObject : null;
  16. }
  17. protected override void OnAddEvent(ReorderableList list)
  18. {
  19. base.OnAddEvent(list);
  20. var listProperty = list.serializedProperty;
  21. if (listProperty.arraySize > 0)
  22. {
  23. var lastCall = list.serializedProperty.GetArrayElementAtIndex(listProperty.arraySize - 1);
  24. var targetProperty = lastCall.FindPropertyRelative(kInstancePath);
  25. targetProperty.objectReferenceValue = FindBoundObject(listProperty);
  26. }
  27. }
  28. protected override void DrawEventHeader(Rect headerRect) {}
  29. protected override void SetupReorderableList(ReorderableList list)
  30. {
  31. base.SetupReorderableList(list);
  32. list.headerHeight = 4;
  33. }
  34. }
  35. }