// Called by the Timeline editor to draw the background of a TweenClip. public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { TweenClip asset = clip.asset as TweenClip; if (asset == null) { return; } PlayableDirector director = TimelineEditor.inspectedDirector; if (director == null) { return; } Transform startLocation = director.GetReferenceValue(asset.startLocation.exposedName, out bool startFound) as Transform; Transform endLocation = director.GetReferenceValue(asset.endLocation.exposedName, out bool endFound) as Transform; if (startFound && startLocation != null) { EditorGUI.LabelField(region.position, startLocation.gameObject.name, s_StartTextStyle); } if (endFound && endLocation != null) { EditorGUI.LabelField(region.position, endLocation.gameObject.name, s_EndTextStyle); } }
//---------------------------------------------------------------------------------------------------------------------- /// <inheritdoc/> public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); Rect rect = region.position; if (rect.width <= SISEditorConstants.MIN_PREVIEW_REGION_WIDTH) { return; } ImageFolderPlayableAsset <T> curAsset = clip.asset as ImageFolderPlayableAsset <T>; if (null == curAsset) { return; } DrawBackgroundTexture(rect, curAsset.GetTimelineBGColor()); int numImages = curAsset.GetNumImages(); if (numImages <= 0) { return; } if (Event.current.type == EventType.Repaint) { PreviewClipInfo clipInfo = new PreviewClipInfo() { Duration = clip.duration, TimeScale = clip.timeScale, ClipIn = clip.clipIn, FramePerSecond = clip.GetParentTrack().timelineAsset.editorSettings.GetFPS(), ImageDimensionRatio = curAsset.GetOrUpdateDimensionRatio(), VisibleLocalStartTime = region.startTime, VisibleLocalEndTime = region.endTime, VisibleRect = rect, }; PreviewUtility.EnumeratePreviewImages(ref clipInfo, (PreviewDrawInfo drawInfo) => { DrawPreviewImageV(ref drawInfo, clip, curAsset); }); //For hiding frame marker automatically PlayableFrameClipData clipData = curAsset.GetBoundClipData(); if (null != clipData) { clipData.UpdateTimelineWidthPerFrame(rect.width, region.endTime - region.startTime, clipInfo.FramePerSecond, clipInfo.TimeScale); } } }
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); if (Application.isPlaying || !TargetPositionCache.UseCache || TargetPositionCache.CacheMode == TargetPositionCache.Mode.Disabled || TimelineEditor.inspectedDirector == null) { return; } // Draw the cache indicator over the cached region var cacheRange = TargetPositionCache.CacheTimeRange; if (!cacheRange.IsEmpty) { cacheRange.Start = (float)TimelineGlobalToLocalTime(cacheRange.Start); cacheRange.End = (float)TimelineGlobalToLocalTime(cacheRange.End); // Clip cacheRange to rect float start = (float)region.startTime; float end = (float)region.endTime; cacheRange.Start = Mathf.Max((float)clip.ToLocalTime(cacheRange.Start), start); cacheRange.End = Mathf.Min((float)clip.ToLocalTime(cacheRange.End), end); var r = region.position; var a = r.x + r.width * (cacheRange.Start - start) / (end - start); var b = r.x + r.width * (cacheRange.End - start) / (end - start); r.x = a; r.width = b - a; r.y += r.height; r.height *= 0.2f; r.y -= r.height; EditorGUI.DrawRect(r, new Color(0.1f, 0.2f, 0.8f, 0.6f)); } // Draw the "UNCACHED" indicator, if appropriate if (!TargetPositionCache.IsRecording && !TargetPositionCache.CurrentPlaybackTimeValid) { var r = region.position; var t = clip.ToLocalTime(TimelineGlobalToLocalTime(TimelineEditor.masterDirector.time)); var pos = r.x + r.width * (float)((t - region.startTime) / (region.endTime - region.startTime)); var s = EditorStyles.miniLabel.CalcSize(kUndamped); r.width = s.x; r.x = pos - r.width / 2; var c = GUI.color; GUI.color = Color.yellow; EditorGUI.LabelField(r, kUndamped, EditorStyles.miniLabel); GUI.color = c; } }
//---------------------------------------------------------------------------------------------------------------------- /// <inheritdoc/> public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); Rect rect = region.position; if (rect.width <= SISEditorConstants.MIN_PREVIEW_REGION_WIDTH) { return; } StreamingImageSequencePlayableAsset curAsset = clip.asset as StreamingImageSequencePlayableAsset; if (null == curAsset || !curAsset.HasImages()) { return; } if (Event.current.type == EventType.Repaint) { PreviewClipInfo clipInfo = new PreviewClipInfo() { Duration = clip.duration, TimeScale = clip.timeScale, ClipIn = clip.clipIn, FramePerSecond = clip.parentTrack.timelineAsset.editorSettings.fps, ImageDimensionRatio = curAsset.GetOrUpdateDimensionRatio(), VisibleLocalStartTime = region.startTime, VisibleLocalEndTime = region.endTime, VisibleRect = rect, }; PreviewUtility.EnumeratePreviewImages(ref clipInfo, (PreviewDrawInfo drawInfo) => { DrawPreviewImage(ref drawInfo, clip, curAsset); }); //For hiding frame marker automatically int numFrames = Mathf.RoundToInt((float)((region.endTime - region.startTime) * clipInfo.FramePerSecond)); double widthPerFrame = rect.width / numFrames; TimelineClipSISData timelineClipSISData = curAsset.GetBoundTimelineClipSISData(); if (null != timelineClipSISData) { timelineClipSISData.SetTimelineWidthPerFrame(widthPerFrame); } } }
//---------------------------------------------------------------------------------------------------------------------- /// <inheritdoc/> public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); Rect rect = region.position; if (rect.width <= SISEditorConstants.MIN_PREVIEW_REGION_WIDTH) { return; } RenderCachePlayableAsset curAsset = clip.asset as RenderCachePlayableAsset; if (null == curAsset) { return; } IList <string> imageFileNames = curAsset.GetImageFileNames(); if (null == imageFileNames || imageFileNames.Count <= 0) { return; } if (Event.current.type == EventType.Repaint) { PreviewClipInfo clipInfo = new PreviewClipInfo() { Duration = clip.duration, TimeScale = clip.timeScale, ClipIn = clip.clipIn, FramePerSecond = clip.parentTrack.timelineAsset.editorSettings.fps, ImageDimensionRatio = curAsset.GetOrUpdateDimensionRatio(), VisibleLocalStartTime = region.startTime, VisibleLocalEndTime = region.endTime, VisibleRect = rect, }; PreviewUtility.EnumeratePreviewImages(ref clipInfo, (PreviewDrawInfo drawInfo) => { DrawPreviewImage(ref drawInfo, clip, curAsset); }); } }
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { AnchorAsset asset = clip.asset as AnchorAsset; Rect rect = region.position; TrackAsset track = clip.parentTrack; target = track as AnchorTrack; if (target != null) { target.RebuildClip(); } if (asset != null) { var quantizedRect = new Rect(Mathf.Ceil(rect.x), Mathf.Ceil(rect.y), Mathf.Ceil(rect.width), Mathf.Ceil(rect.height)); AnimationCurve[] curves = asset.clip_pos; DrawCurve(rect, curves); } }
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); #if CRI_TIMELINE_ATOM_VERBOSE_DEBUG Debug.Log("[CRIWARE][Timeline] DrawBackground"); Debug.Log("region.startTime : " + region.startTime.ToString() + "region.endTime : " + region.endTime.ToString()); #endif CriAtomClip atomClip = clip.asset as CriAtomClip; CriAtomClipWaveformPreviewer atomClipPreviewer; if (!atomClipPreviewDirectory.TryGetValue(atomClip, out atomClipPreviewer)) { #if CRI_TIMELINE_ATOM_VERBOSE_DEBUG Debug.LogError("[CRIWARE][Timeline] not contains key : " + clip.displayName); #endif return; } if (!atomClipPreviewer.HasDecodeTask()) { atomClipPreviewDirectory.Remove(atomClip); atomClipPreviewDirectory.Add(atomClip, new CriAtomClipWaveformPreviewer(atomClip)); } if (!atomClipPreviewer.HasPreviewData()) { /* While decoding or decode error. Skip renderring. */ return; } atomClipPreviewer.IsLooping = atomClip.loopWithinClip; atomClipPreviewer.IsMuted = atomClip.muted; CriAtomTrack atomTrack = clip.parentTrack as CriAtomTrack; if (atomTrack.m_IsRenderMono) { atomClipPreviewer.ChannelMode = CriAtomClipWaveformPreviewer.RenderChannelMode.Mono; } else { atomClipPreviewer.ChannelMode = CriAtomClipWaveformPreviewer.RenderChannelMode.All; } atomClipPreviewer.RenderMaterial(region); }
// Called by the Timeline Editor to draw the background of the timeline clip // when the clip has a VideoPlayableAsset attached public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { VideoPlayableAsset videoAsset = clip.asset as VideoPlayableAsset; if (videoAsset != null && videoAsset.videoClip != null) { // Load the preview or the thumbnail for the video Texture texturePreview = AssetPreview.GetAssetPreview(videoAsset.videoClip); if (texturePreview == null) { texturePreview = AssetPreview.GetMiniThumbnail(videoAsset.videoClip); } if (texturePreview != null) { Rect rect = region.position; rect.width = texturePreview.width * rect.height / texturePreview.height; GUI.DrawTexture(rect, texturePreview, ScaleMode.StretchToFill); } } }
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { var animationTimelineClip = (AnimationTimelineClip <TAnimationBehaviour>)clip.asset; var duration = clip.duration; var behaviour = animationTimelineClip.template; var loopDuration = behaviour.LoopDuration; if (loopDuration <= 0.0f) { return; } if (_pointTexture == null) { _pointTexture = Resources.Load <Texture2D>("tex_unityuiplayables_icon_diamond"); } var time = 0.0f; var position = region.position; position.width = 12; position.height = 12; position.y += position.height / 2; var lengthPerLoop = (float)(region.position.width * loopDuration / duration); while (true) { time += loopDuration; if (time < duration) { position.x += lengthPerLoop; GUI.DrawTexture(position, _pointTexture, ScaleMode.ScaleToFit, true, 1, Color.grey, Vector4.zero, Vector4.zero); } else { break; } } }
//---------------------------------------------------------------------------------------------------------------------- /// <inheritdoc/> public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); SceneCachePlayableAsset asset = clip.asset as SceneCachePlayableAsset; if (null == asset) { Debug.LogError("Asset is not a SceneCachePlayableAsset: " + clip.asset); return; } SceneCacheClipData clipData = asset.GetBoundClipData(); if (null == clipData) return; LimitedAnimationController limitedAnimationController = asset.GetOverrideLimitedAnimationController(); if (!limitedAnimationController.IsEnabled()) { return; } int numFrames = limitedAnimationController.GetNumFramesToHold(); int offset = limitedAnimationController.GetFrameOffset(); GUIStyle style = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.LowerRight, normal = { textColor = new Color(0.3f,0.9f,0.3f), } }; GUIContent laContent = new GUIContent($"Limited: {numFrames}, {offset}"); Vector2 laContentSize = style.CalcSize(laContent); Rect rect = region.position; if (rect.width <= laContentSize.x * 2) //2: arbitrary return; EditorGUI.LabelField(rect, laContent, style); }
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { var playable = clip.asset as VisualEffectControlClip; if (playable.clipEvents == null || playable.singleEvents == null) { return; } var clipEvents = VFXTimeSpaceHelper.GetEventNormalizedSpace(PlayableTimeSpace.AfterClipStart, playable, true); var singleEvents = VFXTimeSpaceHelper.GetEventNormalizedSpace(PlayableTimeSpace.AfterClipStart, playable, false); var allEvents = clipEvents.Concat(singleEvents); //Precompute overlapping data var clipEventBars = ComputeBarClipEvent(clipEvents, out var rowCount); var eventAreaItems = ComputeEventItemArea(region, clip.duration, allEvents, (uint)clipEvents.Count()); //Compute region var clipBarHeight = rowCount * (Style.kMinimalBarHeight + Style.kBarPadding * 2.0f); var eventNameHeight = Style.kEventNameHeight; var scrubbingHeight = playable.scrubbing ? 0.0f : Style.kScrubbingBarHeight; var initialAvailableHeight = region.position.height; var remainingHeight = initialAvailableHeight - (clipBarHeight + scrubbingHeight + eventNameHeight); if (remainingHeight < 0) { remainingHeight = 0.0f; } clipBarHeight += remainingHeight; eventNameHeight = Mathf.Min(eventNameHeight, initialAvailableHeight - clipBarHeight); scrubbingHeight = Mathf.Min(scrubbingHeight, initialAvailableHeight - clipBarHeight - eventNameHeight); var barRegion = new Rect(region.position.position, new Vector2(region.position.width, clipBarHeight)); var eventRegion = new Rect(region.position.position + new Vector2(0, clipBarHeight), new Vector2(region.position.width, eventNameHeight)); var scrubbingRegion = new Rect(region.position.position + new Vector2(0, clipBarHeight + eventNameHeight), new Vector2(region.position.width, scrubbingHeight)); //Draw custom background EditorGUI.DrawRect(region.position, EditorGUIUtility.isProSkin ? Style.kDarkGlobalBackground : Style.kLightGlobalBackground); if (!playable.scrubbing) { EditorGUI.DrawRect(scrubbingRegion, EditorGUIUtility.isProSkin ? Style.kDarkScrubbingBackground : Style.kLightScrubbingBackground); ShadowLabel(scrubbingRegion, Content.scrubbingDisabled, Style.scrubbingDisabled, Style.scrubbingDisabledShadow); } //Draw Clip Bar var rowHeight = clipBarHeight / (float)rowCount; foreach (var bar in clipEventBars) { var relativeStart = InverseLerp(region.startTime, region.endTime, bar.start); var relativeStop = InverseLerp(region.startTime, region.endTime, bar.end); var startRange = region.position.width * Mathf.Clamp01((float)relativeStart); var endRange = region.position.width * Mathf.Clamp01((float)relativeStop); var rect = new Rect( barRegion.x + startRange, barRegion.y + rowHeight * bar.rowIndex + Style.kBarPadding, endRange - startRange, rowHeight - Style.kBarPadding * 2); EditorGUI.DrawRect(rect, bar.color); } //Draw Text Event foreach (var item in eventAreaItems) { var drawRect = item.drawRect; drawRect.position += eventRegion.position; if (item.text) { drawRect.height = eventRegion.height; ShadowLabel(drawRect, item.content, item.textStyle, item.textShadowStyle); } else { var currentType = item.currentType; var baseColor = item.color; if (currentType == IconType.SingleEvent) { //Exception, drawing a kSingleEventWidth px line from here to begin of clip var sourceArea = drawRect; float triangleGap = 0.0f; var middlePosition = sourceArea.position.x + sourceArea.width * 0.5f; var leftRect = new Rect(middlePosition - Style.kSingleEventWidth * triangleGap - Content.clipExitIcon.image.width * Style.kIconScale, sourceArea.y, Content.clipExitIcon.image.width * Style.kIconScale, Content.clipExitIcon.image.height * Style.kIconScale); var rightRect = new Rect(middlePosition + Style.kSingleEventWidth * triangleGap, sourceArea.y, Content.clipEnterIcon.image.width * Style.kIconScale, Content.clipEnterIcon.image.height * Style.kIconScale); GUI.DrawTexture(leftRect, Content.clipExitIcon.image, ScaleMode.StretchToFill, true, 1.0f, baseColor, 0, 0); GUI.DrawTexture(rightRect, Content.clipEnterIcon.image, ScaleMode.StretchToFill, true, 1.0f, baseColor, 0, 0); var middleLineRect = new Rect(middlePosition - Style.kSingleEventWidth * 0.5f, 0.0f, Style.kSingleEventWidth, sourceArea.position.y + sourceArea.height); EditorGUI.DrawRect(middleLineRect, baseColor); } else { GUI.DrawTexture(drawRect, item.content.image, ScaleMode.StretchToFill, true, 1.0f, baseColor, 0, 0); } } } base.DrawBackground(clip, region); }
private List <EventAreaItem> ComputeEventItemArea(ClipBackgroundRegion baseRegion, double maxClipTime, IEnumerable <VisualEffectPlayableSerializedEvent> allEvents, uint clipEventCount) { m_TextEventAreaRequested.Clear(); m_TextEventArea.Clear(); int index = 0; m_TextEventAreaRequested.Clear(); foreach (var itEvent in allEvents) { var timeAfterClamp = Clamp(itEvent.time, 0.0f, maxClipTime); var relativeTime = InverseLerp(baseRegion.startTime, baseRegion.endTime, timeAfterClamp); var currentType = IconType.SingleEvent; if (index < clipEventCount) { currentType = index % 2 == 0 ? IconType.ClipEnter : IconType.ClipExit; } var color = new Color(itEvent.editorColor.r, itEvent.editorColor.g, itEvent.editorColor.b); GUIContent iconContent = null; switch (currentType) { case IconType.ClipEnter: iconContent = Content.clipEnterIcon; break; case IconType.ClipExit: iconContent = Content.clipExitIcon; break; case IconType.SingleEvent: iconContent = Content.singleEventIcon; break; } var iconOffset = 0.0f; switch (currentType) { case IconType.ClipEnter: iconOffset = 0.0f; break; case IconType.ClipExit: iconOffset = -iconContent.image.width * Style.kIconScale; break; case IconType.SingleEvent: iconOffset = -iconContent.image.width * Style.kIconScale * 0.5f; break; } var iconArea = new Rect( baseRegion.position.width * (float)relativeTime + iconOffset, (Style.kEventNameHeight - (iconContent.image.height * Style.kIconScale)) * 0.5f, iconContent.image.width * Style.kIconScale, iconContent.image.height * Style.kIconScale); var icon = new EventAreaItem(iconArea, currentType, iconContent, color); m_TextEventAreaRequested.Add(icon); iconArea.y = 0.0f; var text = new EventAreaItem(iconArea, currentType, (string)itEvent.name); m_TextEventAreaRequested.Add(text); index++; } //Resolve text overlapping m_TextEventArea.Clear(); //Putting all icon foreach (var request in m_TextEventAreaRequested) { var candidate = request; if (!candidate.text) { m_TextEventArea.Add(candidate); } } //Resolve text overlapping foreach (var request in m_TextEventAreaRequested) { var candidate = request; if (candidate.text) { //Trimming text content until it fits while (!string.IsNullOrEmpty(candidate.content.text)) { if (AvailableEmplacement(candidate, m_TextEventArea)) { break; } var newName = candidate.content.text; if (newName.Length > 2) { newName = newName.Substring(0, newName.Length - 2) + "…"; } else { newName = string.Empty; } candidate.content = new GUIContent(newName); candidate.RecomputeRange(); } if (string.IsNullOrEmpty(candidate.content.text)) { continue; //Avoid putting empty range } m_TextEventArea.Add(candidate); } } return(m_TextEventArea); }
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); }
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { if (!(clip.asset is MidiAnimationAsset midiAnimationAsset)) { return; } var midiTrack = midiAnimationAsset.MidiTrack; if (midiTrack == null) { return; } Texture texture; if (_textures.ContainsKey(clip) && _textures[clip] is null) { texture = _textures[clip]; } else { const int topMargin = 2; const int bottomMargin = 1; texture = midiTrack.WriteNoteBarTexture2D((int)midiTrack.DeltaTime / 2, topMargin, bottomMargin); if (_textures.ContainsKey(clip)) { _textures[clip] = texture; } else { _textures.Add(clip, texture); } } Material material; if (_materials.ContainsKey(clip) && _materials[clip] is null) { material = _materials[clip]; } else { var shader = Shader.Find("jp.goma_recorder.Midity.Playable/ClipBackground"); material = new Material(shader) { mainTexture = texture }; if (_materials.ContainsKey(clip)) { _materials[clip] = material; } else { _materials.Add(clip, material); } } var loopCount = (region.endTime - region.startTime) / midiTrack.TotalSeconds; material.SetFloat("_RepeatX", (float)loopCount); material.SetFloat("_OffsetX", (float)(region.startTime / midiTrack.TotalSeconds)); var rect = region.position; var quantizedRect = new Rect(Mathf.Ceil(rect.x), Mathf.Ceil(rect.y), Mathf.Ceil(rect.width), Mathf.Ceil(rect.height)); Graphics.DrawTexture(quantizedRect, texture, material); }