private void RenderTimelineCursor(Rect rect, TimeOfDayController timeController) { // Flag the start of a timeline drag. if (TimelineSelection.isDraggingTimeline == false && (Event.current.type == EventType.MouseDrag) && rect.Contains(Event.current.mousePosition)) { TimelineSelection.isDraggingTimeline = true; } if (TimelineSelection.isDraggingTimeline) { float percent = Mathf.Clamp((Event.current.mousePosition.x - rect.x) / rect.width, 0, MAX_TIME_VALUE); timeController.skyTime = percent; EditorUtility.SetDirty(timeController); } if (Event.current.type != EventType.Repaint) { return; } float playHeadHeight = PLAYHEAD_WIDTH / 2.0f; float xCursorPos = SkyEditorUtility.GetXPositionForPercent(rect, timeController.timeOfDay); // Draw the line that overlaps all the content rows. const float extensionSize = 5.0f; Rect lineRect = new Rect( xCursorPos - (CURSOR_LINE_WIDTH / 2.0f), rect.y + TIME_HEADER_HEIGHT - extensionSize, CURSOR_LINE_WIDTH, rect.height - TIME_HEADER_HEIGHT + extensionSize); GUI.DrawTexture(lineRect, SkyEditorUtility.LoadEditorResourceTexture("CursorLine")); // Draw the playhead arrow. if (m_PlayheadTexture == null) { m_PlayheadTexture = SkyEditorUtility.LoadEditorResourceTexture("PlayheadArrow"); } Rect headRect = new Rect( xCursorPos - (PLAYHEAD_WIDTH / 2.0f), rect.y + TIME_HEADER_HEIGHT - playHeadHeight, PLAYHEAD_WIDTH, playHeadHeight); GUI.DrawTexture(headRect, m_PlayheadTexture, ScaleMode.StretchToFill, true); }
// Sticks to bottom of rect, and can slide horizontally only. public static void DrawHorizontalKeyMarker( Rect fullSliderRect, BaseKeyframe keyFrame, UnityEngine.Object undoObject, out bool didSingleClick, out bool isDragging, out bool keyFrameTimeChanged) { Rect markerRect = new Rect( SkyEditorUtility.GetXPositionForPercent(fullSliderRect, keyFrame.time) - (KEY_GRIP_WIDTH / 2), fullSliderRect.y + fullSliderRect.height - (KEY_GRIP_HEIGHT) / 2.0f, KEY_GRIP_WIDTH, KEY_GRIP_HEIGHT); bool wasDragging = TimelineSelection.selectedControlUUID != null && TimelineSelection.selectedControlUUID == keyFrame.id; bool isMouseOverControl = markerRect.Contains(Event.current.mousePosition); didSingleClick = false; isDragging = wasDragging; keyFrameTimeChanged = false; // Single Click. if (Event.current.isMouse) { // Check for single click, with no drag. if (Event.current.type == EventType.MouseUp && TimelineSelection.selectedControlUUID == null && isMouseOverControl) { Event.current.Use(); didSingleClick = true; } // Start slide. if (TimelineSelection.selectedControlUUID == null && isMouseOverControl && Event.current.type == EventType.MouseDrag) { TimelineSelection.selectedControlUUID = keyFrame.id; Event.current.Use(); isDragging = true; } // End Slide. if (wasDragging && Event.current.type == EventType.MouseUp) { TimelineSelection.selectedControlUUID = null; Event.current.Use(); isDragging = false; } // If we're dragging this keyframe grip, move it's position. if (isDragging || wasDragging) { // Update key frame time value and reposition rectangle. Undo.RecordObject(undoObject, "Keyframe time position changed."); keyFrame.time = SkyEditorUtility.GetPercentForXPosition(fullSliderRect, Event.current.mousePosition.x); keyFrameTimeChanged = true; isDragging = true; // Position the marker rect. markerRect.x = SkyEditorUtility.GetXPositionForPercent(fullSliderRect, keyFrame.time) - (KEY_GRIP_WIDTH / 2); Event.current.Use(); } } bool showAsActive = IsKeyframeActiveInInspector(keyFrame) || isDragging; // Draw the marker at this location. SkyEditorUtility.DrawKeyMarker(markerRect, showAsActive); }
public static void DrawNumericKeyMarker(Rect fullSliderRect, NumberKeyframe keyFrame, NumberKeyframeGroup group, UnityEngine.Object undoObject, out bool didSingleClick, out bool isDragging, out bool keyFrameTimeChanged) { Rect markerRect = new Rect( SkyEditorUtility.GetXPositionForPercent(fullSliderRect, keyFrame.time) - (KEY_GRIP_WIDTH / 2), GetYPositionForPercent(fullSliderRect, 1 - group.ValueToPercent(keyFrame.value)), KEY_GRIP_WIDTH, KEY_GRIP_HEIGHT); bool wasDragging = TimelineSelection.selectedControlUUID != null && TimelineSelection.selectedControlUUID == keyFrame.id; bool isMouseOverControl = markerRect.Contains(Event.current.mousePosition); didSingleClick = false; keyFrameTimeChanged = false; isDragging = wasDragging; // Single Click. if (Event.current.isMouse) { // Check for single click, with no drag. if (Event.current.type == EventType.MouseUp && TimelineSelection.selectedControlUUID == null && isMouseOverControl) { didSingleClick = true; Event.current.Use(); } // Start slide. if (TimelineSelection.selectedControlUUID == null && isMouseOverControl && Event.current.type == EventType.MouseDrag) { TimelineSelection.selectedControlUUID = keyFrame.id; // Find the position of the current value and record the offset so we can drag the keygrip relative from here. Vector2 valuePosition = new Vector2( GetXPositionForPercent(fullSliderRect, keyFrame.time), GetYPositionForPercent(fullSliderRect, 1 - group.ValueToPercent(keyFrame.value))); TimelineSelection.startingMouseOffset = valuePosition - Event.current.mousePosition; isDragging = true; Event.current.Use(); } // End Slide. if (wasDragging && Event.current.type == EventType.MouseUp) { TimelineSelection.selectedControlUUID = null; isDragging = false; Event.current.Use(); } // If we're dragging this keyframe grip, move it's position. if (wasDragging || isDragging) { // Update key frame time value and reposition rectangle. Undo.RecordObject(undoObject, "Keyframe time and value changed."); Vector2 adjustedMousePosition = Event.current.mousePosition + TimelineSelection.startingMouseOffset; keyFrame.time = GetPercentForXPosition(fullSliderRect, adjustedMousePosition.x); float adjustedValuePercent = 1 - GetPercentForYPosition(fullSliderRect, adjustedMousePosition.y); keyFrame.value = group.PercentToValue(adjustedValuePercent); keyFrameTimeChanged = true; isDragging = true; // Position the marker rect. markerRect.x = SkyEditorUtility.GetXPositionForPercent(fullSliderRect, keyFrame.time) - (KEY_GRIP_WIDTH / 2); markerRect.y = GetYPositionForPercent(fullSliderRect, 1 - group.ValueToPercent(keyFrame.value)); Event.current.Use(); } } bool showAsActive = IsKeyframeActiveInInspector(keyFrame) || isDragging; // Draw the marker at this location. SkyEditorUtility.DrawKeyMarker(markerRect, showAsActive); }