/************************************************************************************************************************/ /// <summary> /// Sets the `area` in which the ruler will be drawn and draws a <see cref="GUI.Box(Rect, string)"/> there. /// The returned object must have <see cref="IDisposable.Dispose"/> called on it afterwards. /// </summary> private static IDisposable BeginGUI(Rect area) { if (Current != null) { throw new InvalidOperationException($"{nameof(TimelineGUI)} can't be used recursively."); } if (!EditorGUIUtility.hierarchyMode) { EditorGUI.indentLevel++; } area = EditorGUI.IndentedRect(area); if (!EditorGUIUtility.hierarchyMode) { EditorGUI.indentLevel--; } GUI.Box(area, ""); GUI.BeginClip(area); area.x = area.y = 0; Instance._Area = area; Instance.TickHeight = Mathf.Ceil(area.height * 0.3f); return(Current = Instance); }
/************************************************************************************************************************/ private void DoHeaderGUI(ref Rect area, GUIContent label, Context context) { area.height = AnimancerGUI.LineHeight; var headerArea = area; AnimancerGUI.NextVerticalArea(ref area); label = EditorGUI.BeginProperty(headerArea, label, context.Property); if (!context.Property.hasMultipleDifferentValues) { var addEventArea = AnimancerGUI.StealFromRight(ref headerArea, headerArea.height, AnimancerGUI.StandardSpacing); DoAddRemoveEventButtonGUI(addEventArea, context); } if (context.TransitionContext != null && context.TransitionContext.Transition != null) { EditorGUI.EndProperty(); TimelineGUI.DoGUI(headerArea, context, out var addEventNormalizedTime); if (!float.IsNaN(addEventNormalizedTime)) { AddEvent(context, addEventNormalizedTime); } } else { label.text = AnimancerGUI.GetNarrowText(label.text); string summary; if (context.Times.Count == 0) { summary = "[0] End Time 1"; } else { var index = context.Times.Count - 1; var endTime = context.Times.GetElement(index).floatValue; summary = $"[{index}] End Time {endTime:G3}"; } using (ObjectPool.Disposable.AcquireContent(out var content, summary)) EditorGUI.LabelField(headerArea, label, content); EditorGUI.EndProperty(); } EditorGUI.BeginChangeCheck(); context.Property.isExpanded = EditorGUI.Foldout(headerArea, context.Property.isExpanded, GUIContent.none, true); if (EditorGUI.EndChangeCheck()) { context.SelectedEvent = -1; } }
/// <summary>Ends the area started by <see cref="BeginGUI"/>.</summary> void IDisposable.Dispose() { Current = null; GUI.EndClip(); }