コード例 #1
0
        // 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);
        }
コード例 #2
0
        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);
        }