TimelineChildEditor.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEditor;
  2. using UnityEngine;
  3. using System.Linq;
  4. namespace Chronos
  5. {
  6. [CustomEditor(typeof(TimelineChild)), CanEditMultipleObjects]
  7. public class TimelineChildEditor : Editor
  8. {
  9. protected SerializedProperty recordingInterval;
  10. public void OnEnable()
  11. {
  12. recordingInterval = serializedObject.FindProperty("_recordingInterval");
  13. }
  14. public override void OnInspectorGUI()
  15. {
  16. serializedObject.Update();
  17. bool anyRewindable = serializedObject.targetObjects.OfType<TimelineChild>().Any(tc =>
  18. {
  19. var t = tc.GetComponentInParent<Timeline>();
  20. return t != null && t.rewindable;
  21. });
  22. EditorGUI.BeginDisabledGroup(Application.isPlaying);
  23. {
  24. if (anyRewindable)
  25. {
  26. EditorGUILayout.PropertyField(recordingInterval, new GUIContent("Recording Interval"));
  27. }
  28. }
  29. EditorGUI.EndDisabledGroup();
  30. if (anyRewindable)
  31. {
  32. float estimate = serializedObject.targetObjects.OfType<TimelineChild>().Select(tc => tc.EstimateMemoryUsage()).Sum() / 1024;
  33. EditorGUILayout.HelpBox(string.Format("Estimated memory: {0} KiB.", estimate), MessageType.Info);
  34. }
  35. serializedObject.ApplyModifiedProperties();
  36. }
  37. }
  38. }