/// <summary>Calculates the number of lines required to draw the contents of the `events`.</summary> public int CalculateLineCount(Sequence events) { if (events == null) { return(0); } if (!_IsExpanded) { return(1); } var count = 1; for (int i = 0; i < events.Count; i++) { count++; count += CalculateLineCount(events[i].callback); } count++; count += CalculateLineCount(events.endEvent.callback); return(count); }
/// <summary>Returns a summary of the `events`.</summary> public static string GetSummary(Sequence events) { var cache = float.IsNaN(events.endEvent.normalizedTime) && AnimancerEvent.IsNullOrDummy(events.endEvent.callback) ? SummaryCache : EndSummaryCache; return(cache.Convert(events.Count)); }
/// <summary>Returns a cached <see cref="EventSequenceDrawer"/> for the `events`.</summary> /// <remarks> /// The cache uses a <see cref="ConditionalWeakTable{TKey, TValue}"/> so it doesn't prevent the `events` /// from being garbage collected. /// </remarks> public static EventSequenceDrawer Get(Sequence events) { if (events == null) { return(null); } if (!SequenceToDrawer.TryGetValue(events, out var drawer)) { SequenceToDrawer.Add(events, drawer = new EventSequenceDrawer()); } return(drawer); }
/************************************************************************************************************************/ /// <summary>Draws the GUI for the `events`.</summary> public void Draw(ref Rect area, Sequence events, GUIContent label) { if (events == null) { return; } area.height = AnimancerGUI.LineHeight; var headerArea = area; const string LogLabel = "Log"; if (float.IsNaN(_LogButtonWidth)) { _LogButtonWidth = EditorStyles.miniButton.CalculateWidth(LogLabel); } var logArea = AnimancerGUI.StealFromRight(ref headerArea, _LogButtonWidth); if (GUI.Button(logArea, LogLabel, EditorStyles.miniButton)) { Debug.Log(events.DeepToString()); } _IsExpanded = EditorGUI.Foldout(headerArea, _IsExpanded, GUIContent.none, true); using (ObjectPool.Disposable.AcquireContent(out var summary, GetSummary(events))) EditorGUI.LabelField(headerArea, label, summary); AnimancerGUI.NextVerticalArea(ref area); if (!_IsExpanded) { return; } var enabled = GUI.enabled; GUI.enabled = false; EditorGUI.indentLevel++; for (int i = 0; i < events.Count; i++) { var name = events.GetName(i); if (string.IsNullOrEmpty(name)) { if (_EventNumberCache == null) { _EventNumberCache = new ConversionCache <int, string>((index) => $"Event {index}"); } name = _EventNumberCache.Convert(i); } Draw(ref area, name, events[i]); } Draw(ref area, "End Event", events.endEvent); EditorGUI.indentLevel--; GUI.enabled = enabled; }
/************************************************************************************************************************/ /// <summary>Calculates the number of vertical pixels required to draw the contents of the `events`.</summary> public float CalculateHeight(Sequence events) => CalculateHeight(CalculateLineCount(events));