GroupTrackInspector.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //#define PERF_PROFILE
  2. using System.Linq;
  3. using UnityEditorInternal;
  4. using UnityEngine;
  5. using UnityEngine.Timeline;
  6. namespace UnityEditor.Timeline
  7. {
  8. [CustomEditor(typeof(GroupTrack)), CanEditMultipleObjects]
  9. class GroupTrackInspector : TrackAssetInspector
  10. {
  11. static class Styles
  12. {
  13. public static readonly GUIContent GroupSubTrackHeaderName = EditorGUIUtility.TrTextContent("Name");
  14. public static readonly GUIContent GroupSubTrackHeaderType = EditorGUIUtility.TrTextContent("Type");
  15. public static readonly GUIContent GroupSubTrackHeaderDuration = EditorGUIUtility.TrTextContent("Duration");
  16. public static readonly GUIContent GroupSubTrackHeaderFrames = EditorGUIUtility.TrTextContent("Frames");
  17. public static readonly GUIContent GroupInvalidTrack = EditorGUIUtility.TrTextContent("Invalid Track");
  18. }
  19. ReorderableList m_SubTracks;
  20. public override void OnInspectorGUI()
  21. {
  22. foreach (var group in targets)
  23. {
  24. var groupTrack = group as GroupTrack;
  25. if (groupTrack == null) return;
  26. var childrenTracks = groupTrack.GetChildTracks();
  27. var groupTrackName = groupTrack.name;
  28. GUILayout.Label(childrenTracks.Count() > 0
  29. ? groupTrackName + " (" + childrenTracks.Count() + ")"
  30. : groupTrackName, EditorStyles.boldLabel);
  31. GUILayout.Space(3.0f);
  32. // the subTrackObjects is used because it's the internal list
  33. m_SubTracks.list = groupTrack.subTracksObjects;
  34. m_SubTracks.DoLayoutList();
  35. m_SubTracks.index = -1;
  36. }
  37. }
  38. public override void OnEnable()
  39. {
  40. base.OnEnable();
  41. m_SubTracks = new ReorderableList(new string[] {}, typeof(string), false, true, false, false)
  42. {
  43. drawElementCallback = OnDrawSubTrack,
  44. drawHeaderCallback = OnDrawHeader,
  45. showDefaultBackground = true,
  46. index = 0,
  47. elementHeight = 20
  48. };
  49. }
  50. static void OnDrawHeader(Rect rect)
  51. {
  52. int sections = 4;
  53. float sectionWidth = rect.width / sections;
  54. rect.width = sectionWidth;
  55. GUI.Label(rect, Styles.GroupSubTrackHeaderName, EditorStyles.label);
  56. rect.x += sectionWidth;
  57. GUI.Label(rect, Styles.GroupSubTrackHeaderType, EditorStyles.label);
  58. rect.x += sectionWidth;
  59. GUI.Label(rect, Styles.GroupSubTrackHeaderDuration, EditorStyles.label);
  60. rect.x += sectionWidth;
  61. GUI.Label(rect, Styles.GroupSubTrackHeaderFrames, EditorStyles.label);
  62. }
  63. void OnDrawSubTrack(Rect rect, int index, bool selected, bool focused)
  64. {
  65. int sections = 4;
  66. float sectionWidth = rect.width / sections;
  67. var childrenTrack = m_SubTracks.list[index] as TrackAsset;
  68. if (childrenTrack == null)
  69. {
  70. object o = m_SubTracks.list[index];
  71. rect.width = sectionWidth;
  72. if (o != null) // track is loaded, but has broken script
  73. {
  74. string name = ((UnityEngine.Object)m_SubTracks.list[index]).name;
  75. GUI.Label(rect, name, EditorStyles.label);
  76. }
  77. rect.x += sectionWidth;
  78. using (new GUIColorOverride(DirectorStyles.kClipErrorColor))
  79. GUI.Label(rect, Styles.GroupInvalidTrack.text, EditorStyles.label);
  80. return;
  81. }
  82. rect.width = sectionWidth;
  83. GUI.Label(rect, childrenTrack.name, EditorStyles.label);
  84. rect.x += sectionWidth;
  85. GUI.Label(rect, childrenTrack.GetType().Name, EditorStyles.label);
  86. rect.x += sectionWidth;
  87. GUI.Label(rect, childrenTrack.duration.ToString(), EditorStyles.label);
  88. rect.x += sectionWidth;
  89. double exactFrames = TimeUtility.ToExactFrames(childrenTrack.duration, TimelineWindow.instance.state.referenceSequence.frameRate);
  90. GUI.Label(rect, exactFrames.ToString(), EditorStyles.label);
  91. }
  92. }
  93. }