static void DrawClipEditorBackground(ClipDrawData drawData) { var isRepaint = (Event.current.type == EventType.Repaint); if (isRepaint && drawData.clipEditor != null) { var customBodyRect = drawData.clippedRect; customBodyRect.yMin += k_ClipInlineWidth; customBodyRect.yMax -= k_ClipSwatchLineThickness; var region = new ClipBackgroundRegion(customBodyRect, drawData.localVisibleStartTime, drawData.localVisibleEndTime); try { drawData.clipEditor.DrawBackground(drawData.clip, region); } catch (Exception e) { Debug.LogException(e); } } }
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { if (!TimelineWindow.instance.state.showAudioWaveform) { return; } var rect = region.position; if (rect.width <= 0) { return; } var audioClip = clip.asset as AudioClip; if (audioClip == null) { var audioPlayableAsset = clip.asset as AudioPlayableAsset; if (audioPlayableAsset != null) { audioClip = audioPlayableAsset.clip; } } if (audioClip == null) { return; } var quantizedRect = new Rect(Mathf.Ceil(rect.x), Mathf.Ceil(rect.y), Mathf.Ceil(rect.width), Mathf.Ceil(rect.height)); WaveformPreview preview = GetOrCreateWaveformPreview(clip, audioClip, quantizedRect, region.startTime, region.endTime); if (Event.current.type == EventType.Repaint) { DrawWaveformPreview(preview, quantizedRect); } }
/// <summary> /// Compares this object with another <c>ClipBackgroundRegion</c>. /// </summary> /// <param name="other">The object to compare with.</param> /// <returns>Returns true if <c>this</c> and <paramref name="other"/> are equal.</returns> public bool Equals(ClipBackgroundRegion other) { return(position.Equals(other.position) && startTime == other.startTime && endTime == other.endTime); }
/// <summary> /// Override this method to draw a background for a clip . /// </summary> /// <param name="clip">The clip being drawn.</param> /// <param name="region">The on-screen area where the clip is drawn.</param> public virtual void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { }
public static void DrawDefaultClip(ClipDrawData drawData) { DrawClipBackground(drawData.clipCenterSection, drawData.clipBlends, drawData.selected); if (drawData.targetRect.width > k_MinClipWidth) { var isRepaint = (Event.current.type == EventType.Repaint); if (isRepaint && drawData.clipEditor != null) { var customBodyRect = drawData.clippedRect; customBodyRect.yMin += k_ClipInlineWidth; customBodyRect.yMax -= k_ClipSwatchLineThickness; var region = new ClipBackgroundRegion(customBodyRect, drawData.localVisibleStartTime, drawData.localVisibleEndTime); try { drawData.clipEditor.DrawBackground(drawData.clip, region); } catch (Exception e) { Debug.LogException(e); } } } else { drawData.targetRect.width = k_MinClipWidth; drawData.clipCenterSection.width = k_MinClipWidth; } DrawClipEdges(drawData.targetRect, drawData.ClipDrawOptions.highlightColor, s_InlineLightColor, s_InlineShadowColor, drawData.clipBlends.inKind != BlendKind.Mix, drawData.clipBlends.outKind != BlendKind.Mix); DrawClipTimescale(drawData.targetRect, drawData.clip.timeScale); if (drawData.targetRect.width >= k_ClipInOutMinWidth) { DrawClipInOut(drawData.targetRect, drawData.clip); } var labelRect = drawData.clipCenterSection; if (drawData.targetRect.width >= k_ClipLoopsMinWidth) { bool selected = drawData.selected || drawData.inlineCurvesSelected; if (selected) { if (drawData.loopRects != null && drawData.loopRects.Any()) { DrawLoops(drawData); var l = drawData.loopRects[0]; labelRect.xMax = Math.Min(labelRect.xMax, l.x - drawData.unclippedRect.x); } } } labelRect.xMin += k_ClipLabelPadding; labelRect.xMax -= k_ClipLabelPadding; if (labelRect.width > k_ClipLabelMinWidth) { DrawClipLabel(drawData, labelRect, Color.white); } DrawClipBorder(drawData); }
/// <inheritdoc/> public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { if (!TimelineWindow.instance.state.showAudioWaveform) { return; } var rect = region.position; if (rect.width <= 0) { return; } var audioClip = clip.asset as AudioClip; if (audioClip == null) { var audioPlayableAsset = clip.asset as AudioPlayableAsset; if (audioPlayableAsset != null) { audioClip = audioPlayableAsset.clip; } } if (audioClip == null) { return; } var quantizedRect = new Rect(Mathf.Ceil(rect.x), Mathf.Ceil(rect.y), Mathf.Ceil(rect.width), Mathf.Ceil(rect.height)); WaveformPreview preview; if (QualitySettings.activeColorSpace != m_ColorSpace) { m_ColorSpace = QualitySettings.activeColorSpace; m_PersistentPreviews.Clear(); } if (!m_PersistentPreviews.TryGetValue(clip, out preview) || audioClip != preview.presentedObject) { preview = m_PersistentPreviews[clip] = WaveformPreviewFactory.Create((int)quantizedRect.width, audioClip); Color waveColour = GammaCorrect(DirectorStyles.Instance.customSkin.colorAudioWaveform); Color transparent = waveColour; transparent.a = 0; preview.backgroundColor = transparent; preview.waveColor = waveColour; preview.SetChannelMode(WaveformPreview.ChannelMode.MonoSum); preview.updated += () => TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw); } preview.looping = clip.SupportsLooping(); preview.SetTimeInfo(region.startTime, region.endTime - region.startTime); preview.OptimizeForSize(quantizedRect.size); if (Event.current.type == EventType.Repaint) { preview.ApplyModifications(); preview.Render(quantizedRect); } }