/// <summary>Draws a button to add a new event.</summary> public void DoAddEventButtonGUI(Rect area, Context context) { if (!GUI.Button(area, AddEventContent, Styles.AddEventStyle)) { return; } // If the target is currently being previewed, add the event at the currently selected time. var state = TransitionPreviewWindow.GetCurrentState(); var normalizedTime = state != null ? state.NormalizedTime : float.NaN; AddEvent(context, normalizedTime); }
/// <summary>Draws a button to add a new event or remove the selected one.</summary> public void DoAddRemoveEventButtonGUI(Rect area, Context context) { if (_AddRemoveEventStyle == null) { _AddRemoveEventStyle = new GUIStyle(EditorStyles.miniButton) { fixedHeight = 0, } } ; if (ShowAddButton(context)) { if (_AddEventContent == null) { _AddEventContent = EditorGUIUtility.IconContent("Animation.AddEvent", Strings.ProOnlyTag + "Add event"); } _AddRemoveEventStyle.padding = new RectOffset(-1, 1, 0, 0); if (GUI.Button(area, _AddEventContent, _AddRemoveEventStyle)) { // If the target is currently being previewed, add the event at the currently selected time. var state = TransitionPreviewWindow.GetCurrentState(); var normalizedTime = state != null ? state.NormalizedTime : float.NaN; AddEvent(context, normalizedTime); } } else { _AddRemoveEventStyle.padding = new RectOffset(1, 1, 0, 0); using (ObjectPool.Disposable.AcquireContent(out var content, "X", "Remove selected event")) { if (GUI.Button(area, content, _AddRemoveEventStyle)) { RemoveEvent(context, context.SelectedEvent); } } } }
/************************************************************************************************************************/ private void DrawPreviewTime() { var state = TransitionPreviewWindow.GetCurrentState(); if (state == null) { return; } var normalizedTime = TransitionPreviewWindow.PreviewNormalizedTime; DrawPreviewTime(normalizedTime, alpha: 1); // Looping states show faded indicators at every other multiple of the loop. if (!state.IsLooping) { return; } // Make sure the area is actually wide enough for it to not just be a solid bar. if ((int)SecondsToPixels(0) > (int)SecondsToPixels(_Duration) - 4) { return; } // Go back to the first visible increment. while (normalizedTime * _Duration >= _MinTime + _Duration) { normalizedTime -= 1; } // Draw every visible increment from there on. while (normalizedTime * _Duration <= _MaxTime) { DrawPreviewTime(normalizedTime, alpha: 0.2f); normalizedTime += 1; } }
/// <summary> /// Draws ticks and labels for important times throughout the area. /// </summary> public void DoRulerGUI() { if (Event.current.type != EventType.Repaint) { return; } var tickHeight = Mathf.Ceil(_Area.height * TickHeight); var area = new Rect(SecondsToPixels(0), _Area.yMax - tickHeight, 0, tickHeight) { xMax = SecondsToPixels(_Duration) }; #if !UNITY_2019_1_OR_NEWER area.height++; #endif EditorGUI.DrawRect(area, BaseTimeColor); TickTimes.Clear(); TickTimes.Add(0); TickTimes.Add(_StartTime); TickTimes.Add(_FadeInEnd); TickTimes.Add(_Duration); TickTimes.AddRange(EventTimes); TickTimes.Sort(); var previousTime = float.NaN; area.x = float.NegativeInfinity; for (int i = 0; i < TickTimes.Count; i++) { var time = TickTimes[i]; if (previousTime != time) { previousTime = time; DoRulerLabelGUI(ref area, time); } } var state = TransitionPreviewWindow.GetCurrentState(); if (state != null) { var normalizedTime = TransitionPreviewWindow.PreviewNormalizedTime; DrawPreviewTime(normalizedTime, 1); if (state.IsLooping) { if ((int)SecondsToPixels(0) <= (int)SecondsToPixels(_Duration) + 2) { return; } while (normalizedTime * _Duration >= _MinTime + _Duration) { normalizedTime -= 1; } while (normalizedTime * _Duration <= _MaxTime) { DrawPreviewTime(normalizedTime, 0.25f); normalizedTime += 1; } } } }
/// <summary> /// Draws ticks and labels for important times throughout the area. /// </summary> public void DoRulerGUI() { if (Event.current.type != EventType.Repaint) { return; } var tickHeight = _Area.height * TickHeight; var area = new Rect(SecondsToPixels(0), _Area.yMax - tickHeight, 0, tickHeight) { xMax = SecondsToPixels(_Duration) }; EditorGUI.DrawRect(area, BaseTimeColor); TickTimes.Clear(); TickTimes.Add(0); TickTimes.Add(_StartTime); TickTimes.Add(_FadeInEnd); TickTimes.Add(_Duration); for (int i = 0; i < EventTimes.Count; i++) { TickTimes.Add(EventTimes[i]); } TickTimes.Sort(); var previousTime = float.NaN; area.x = float.NegativeInfinity; for (int i = 0; i < TickTimes.Count; i++) { var time = TickTimes[i]; if (previousTime != time) { previousTime = time; DoRulerLabelGUI(ref area, time); } } var state = TransitionPreviewWindow.GetCurrentState(); if (state != null) { var time = state.Time; DrawPreviewTime(time, 1); if (state.IsLooping) { while (time >= _MinTime + _Duration) { time -= _Duration; } while (time <= _MaxTime) { DrawPreviewTime(time, 0.25f); time += _Duration; } } } }