public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var previousTimeSpace = (PlayableTimeSpace)property.enumValueIndex; var newTimeSpace = (PlayableTimeSpace)EditorGUI.EnumPopup(position, label, previousTimeSpace); if (previousTimeSpace != newTimeSpace) { property.enumValueIndex = (int)newTimeSpace; var parentEventPath = property.propertyPath.Substring(0, property.propertyPath.Length - nameof(VisualEffectPlayableSerializedEvent.timeSpace).Length - 1); var parentEvent = property.serializedObject.FindProperty(parentEventPath); if (parentEvent == null) throw new InvalidOperationException(); var parentEventTime = parentEvent.FindPropertyRelative(nameof(VisualEffectPlayableSerializedEvent.time)); if (parentEventTime == null) throw new InvalidOperationException(); var parentPlayable = property.serializedObject.targetObject as VisualEffectControlClip; if (parentPlayable == null) throw new InvalidOperationException(); var oldTime = parentEventTime.doubleValue; var newTime = VFXTimeSpaceHelper.GetTimeInSpace(previousTimeSpace, oldTime, newTimeSpace, parentPlayable.clipStart, parentPlayable.clipEnd); parentEventTime.doubleValue = newTime; } }
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); }