Exemplo n.º 1
0
        private bool RenderNumericGUI()
        {
            NumberKeyframe numberKeyframe = keyframe as NumberKeyframe;

            if (numberKeyframe == null)
            {
                return(false);
            }

            NumberKeyframeGroup numberGroup = @group as NumberKeyframeGroup;

            if (numberGroup == null)
            {
                return(false);
            }

            bool didModify = false;

            EditorGUI.BeginChangeCheck();
            float value = EditorGUILayout.FloatField(new GUIContent("Value"), numberKeyframe.value);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(profile, "Keyframe numeric value changed.");
                numberKeyframe.value = Mathf.Clamp(value, numberGroup.minValue, numberGroup.maxValue);
                didModify            = true;
            }

            return(didModify);
        }
Exemplo n.º 2
0
        private void InsertKeyframeInNumericGroup(float time, NumberKeyframeGroup group)
        {
            NumberKeyframe previousKeyframe = group.GetPreviousKeyFrame(time);
            NumberKeyframe newKeyFrame      = new NumberKeyframe(previousKeyframe);

            newKeyFrame.time = time;
            group.AddKeyFrame(newKeyFrame);

            KeyframeInspectorWindow.SetKeyframeData(
                newKeyFrame, group, KeyframeInspectorWindow.KeyType.Numeric, m_ActiveSkyProfile);
        }
Exemplo n.º 3
0
        // Use vertex shader to fix aspect ratio.
        public static void RenderNumberGroup(Rect rect, SkyProfile profile, NumberKeyframeGroup group)
        {
            lock (profile) {
                bool sortKeyFrames = false;

                RenderLinePath(rect, group);

                for (int i = 0; i < group.keyframes.Count; i++)
                {
                    NumberKeyframe currentKey = group.GetKeyframe(i);

                    int            nextIndex = (i + 1) % group.keyframes.Count;
                    NumberKeyframe nextKey   = group.GetKeyframe(nextIndex);

                    // Clamp time if we're wrapping around.
                    float nextTime = nextKey.time;
                    if (nextTime <= currentKey.time)
                    {
                        nextTime = 1.0f;
                    }

                    bool didSingleClick  = false;
                    bool isDragging      = false;
                    bool keyframeUpdated = false;

                    SkyEditorUtility.DrawNumericKeyMarker(rect, currentKey, group, profile,
                                                          out didSingleClick, out isDragging, out keyframeUpdated);

                    if (keyframeUpdated)
                    {
                        sortKeyFrames = true;
                    }

                    if (didSingleClick || isDragging)
                    {
                        KeyframeInspectorWindow.SetKeyframeData(
                            currentKey, group, KeyframeInspectorWindow.KeyType.Numeric, profile);

                        if (didSingleClick && KeyframeInspectorWindow.inspectorEnabled == false)
                        {
                            KeyframeInspectorWindow.ShowWindow();
                        }
                    }
                }

                if (sortKeyFrames)
                {
                    group.SortKeyframes();
                }
            }
        }
Exemplo n.º 4
0
        // Render numeric properties with a slider.
        public bool RenderNumericGroupProperty(ProfileGroupDefinition def)
        {
            EditorGUILayout.BeginHorizontal();
            NumberKeyframeGroup group = m_Profile.GetGroup <NumberKeyframeGroup>(def.propertyKey);

            EditorGUILayout.PrefixLabel(new GUIContent(group.name, def.tooltip));
            bool valueChanged = false;

            if (m_Profile.IsManagedByTimeline(def.propertyKey))
            {
                RenderManagedOnTimlineMessage();
            }
            else
            {
                NumberKeyframe frame = group.GetKeyframe(0);

                if (def.formatStyle == ProfileGroupDefinition.FormatStyle.Integer)
                {
                    EditorGUI.BeginChangeCheck();
                    int value = EditorGUILayout.IntField((int)frame.value);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(m_Profile, "Changed int keyframe value");
                        frame.value  = (int)Mathf.Clamp(value, group.minValue, group.maxValue);
                        valueChanged = true;
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    float value = EditorGUILayout.Slider(frame.value, group.minValue, group.maxValue);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(m_Profile, "Changed float keyframe value");
                        frame.value  = value;
                        valueChanged = true;
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            return(valueChanged);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 public NumberKeyframe(NumberKeyframe keyframe) : base(keyframe.time)
 {
     this.value             = keyframe.value;
     interpolationCurve     = keyframe.interpolationCurve;
     interpolationDirection = keyframe.interpolationDirection;
 }