public static double FromTimeString(this TimeFormat timeFormat, string timeString, double frameRate, double defaultValue)
        {
            double time = defaultValue;

            switch (timeFormat)
            {
            case TimeFormat.Frames:
                if (!double.TryParse(timeString, NumberStyles.Any, CultureInfo.InvariantCulture, out time))
                {
                    return(defaultValue);
                }
                time = TimeUtility.FromFrames(time, frameRate);
                break;

            case TimeFormat.Seconds:
                time = TimeUtility.ParseTimeSeconds(timeString, frameRate, defaultValue);
                break;

            case TimeFormat.Timecode:
                time = TimeUtility.ParseTimeCode(timeString, frameRate, defaultValue);
                break;

            default:
                time = defaultValue;
                break;
            }

            return(time);
        }
Exemple #2
0
        public static double FromTimeString(string timeString)
        {
            double newTime;

            if (state.timeInFrames)
            {
                double newFrameDouble;
                if (double.TryParse(timeString, out newFrameDouble))
                {
                    newTime = TimeUtility.FromFrames(newFrameDouble, state.referenceSequence.frameRate);
                }
                else
                {
                    newTime = state.editSequence.time;
                }
            }
            else
            {
                newTime = TimeUtility.ParseTimeCode(timeString, state.referenceSequence.frameRate, -1);
            }

            if (newTime >= 0.0)
            {
                return(state.timeReferenceMode == TimeReferenceMode.Global ?
                       state.editSequence.ToLocalTime(newTime) : newTime);
            }

            return(state.editSequence.time);
        }
Exemple #3
0
        public override bool Execute(ActionContext actionContext)
        {
            if (TimelineEditor.inspectedAsset == null)
            {
                return(false);
            }
            var inspectedFrame = TimeUtility.ToFrames(TimelineEditor.inspectedSequenceTime, TimelineEditor.inspectedAsset.editorSettings.fps);

            inspectedFrame++;
            TimelineEditor.inspectedSequenceTime = TimeUtility.FromFrames(inspectedFrame, TimelineEditor.inspectedAsset.editorSettings.fps);
            return(true);
        }
Exemple #4
0
        public static double FromTimeString(this TimeFormat timeFormat, string timeString, double frameRate, double defaultValue)
        {
            if (timeFormat == TimeFormat.Frames)
            {
                double time;
                if (!double.TryParse(timeString, NumberStyles.Any, CultureInfo.InvariantCulture, out time))
                {
                    return(defaultValue);
                }
                return(TimeUtility.FromFrames(time, frameRate));
            }

            // this handles seconds or timecode based on the formatting (. vs :)
            return(TimeUtility.ParseTimeCode(timeString, frameRate, defaultValue));
        }
Exemple #5
0
 public double ApplyOffset(double currentValue, float delta, TimelineWindow.TimelineState state)
 {
     if (state.frameSnap)
     {
         double num = currentValue;
         this.m_LastOffsetApplied = 0.0;
         bool flag = true;
         this.m_CurrentOffset += (double)delta;
         if (!TimeUtility.OnFrameBoundary(currentValue, (double)state.frameRate))
         {
             double frames = TimeUtility.ToExactFrames(currentValue, (double)state.frameRate) - (double)TimeUtility.ToFrames(currentValue, (double)state.frameRate);
             double num2   = TimeUtility.FromFrames(frames, (double)state.frameRate);
             if (Math.Abs(this.m_CurrentOffset) >= Math.Abs(num2))
             {
                 currentValue         += num2;
                 this.m_CurrentOffset -= num2;
             }
             else
             {
                 flag = false;
             }
         }
         if (flag)
         {
             double num3 = (double)TimeUtility.ToFrames(this.m_CurrentOffset, (double)state.frameRate);
             this.m_CurrentOffset = TimeUtility.FromFrames(TimeUtility.ToExactFrames(this.m_CurrentOffset, (double)state.frameRate) - num3, (double)state.frameRate);
             currentValue         = TimeUtility.FromFrames(num3 + (double)TimeUtility.ToFrames(currentValue, (double)state.frameRate), (double)state.frameRate);
         }
         this.m_LastOffsetApplied = currentValue - num;
     }
     else
     {
         this.m_LastOffsetApplied = (double)delta;
         currentValue            += (double)delta;
     }
     return(currentValue);
 }
Exemple #6
0
        public static bool NudgeClip(TimelineClip clip, TimelineWindow.TimelineState state, double offset)
        {
            bool result;

            if (clip == null)
            {
                result = false;
            }
            else
            {
                TimelineUndo.PushUndo(clip.parentTrack, "Nudge Clip");
                if (state.frameSnap)
                {
                    clip.start = TimeUtility.FromFrames(Math.Max((double)TimeUtility.ToFrames(clip.start, (double)state.frameRate) + offset, 0.0), (double)state.frameRate);
                }
                else
                {
                    clip.start += Math.Max(offset / (double)state.frameRate, 0.0);
                }
                EditorUtility.SetDirty(clip.parentTrack);
                result = true;
            }
            return(result);
        }
Exemple #7
0
        // Display Time related properties in frames and seconds
        public static void TimeField(Rect rect, SerializedProperty property, GUIContent label, bool readOnly, double frameRate, double minValue, double maxValue, ref InputEvent inputEvent)
        {
            using (var propertyScope = new PropertyScope(rect, label, property))
            {
                GUIContent title = propertyScope.content;
                rect = EditorGUI.PrefixLabel(rect, title);

                using (new IndentLevelScope(0))
                    using (new LabelWidthScope((int)EditorGUI.kMiniLabelW))
                        using (new GUIMixedValueScope(property.hasMultipleDifferentValues))
                        {
                            var secondsRect = new Rect(rect.xMin, rect.yMin, rect.width / 2 - EditorGUI.kSpacingSubLabel, rect.height);
                            var framesRect  = new Rect(rect.xMin + rect.width / 2, rect.yMin, rect.width / 2, rect.height);

                            if (readOnly)
                            {
                                EditorGUI.FloatField(secondsRect, Styles.SecondsPrefix, (float)property.doubleValue, EditorStyles.label);
                            }
                            else
                            {
                                EditorGUI.BeginChangeCheck();
                                DelayedAndDraggableDoubleField(secondsRect, Styles.SecondsPrefix, property, ref inputEvent);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    property.doubleValue = Clamp(property.doubleValue, minValue, maxValue);
                                }
                            }

                            if (frameRate > TimeUtility.kTimeEpsilon)
                            {
                                EditorGUI.BeginChangeCheck();

                                double time        = property.doubleValue;
                                int    frames      = TimeUtility.ToFrames(time, frameRate);
                                double exactFrames = TimeUtility.ToExactFrames(time, frameRate);
                                bool   useIntField = TimeUtility.OnFrameBoundary(time, frameRate);

                                if (readOnly)
                                {
                                    if (useIntField)
                                    {
                                        EditorGUI.IntField(framesRect, Styles.FramesPrefix, frames, EditorStyles.label);
                                    }
                                    else
                                    {
                                        EditorGUI.DoubleField(framesRect, Styles.FramesPrefix, exactFrames, EditorStyles.label);
                                    }
                                }
                                else
                                {
                                    if (useIntField)
                                    {
                                        int newFrames = DelayedAndDraggableIntField(framesRect, Styles.FramesPrefix, frames, ref inputEvent);
                                        time = Math.Max(0, TimeUtility.FromFrames(newFrames, frameRate));
                                    }
                                    else
                                    {
                                        double newExactFrames = DelayedAndDraggableDoubleField(framesRect, Styles.FramesPrefix, exactFrames, ref inputEvent);
                                        time = Math.Max(0, TimeUtility.FromFrames((int)Math.Floor(newExactFrames), frameRate));
                                    }
                                }

                                if (EditorGUI.EndChangeCheck())
                                {
                                    property.doubleValue = Clamp(time, minValue, maxValue);
                                }
                            }
                        }
            }
        }
Exemple #8
0
        public static double TimeField(Rect rect, GUIContent label, double time, bool readOnly, bool showMixed, double frameRate, double minValue, double maxValue, ref InputEvent inputEvent)
        {
            using (new HorizontalScope(label, GUIStyle.none))
            {
                rect = EditorGUI.PrefixLabel(rect, label);

                using (new IndentLevelScope(0))
                    using (new LabelWidthScope((int)EditorGUI.kMiniLabelW))
                        using (new GUIMixedValueScope(showMixed))
                        {
                            var secondsRect = new Rect(rect.xMin, rect.yMin, rect.width / 2 - EditorGUI.kSpacingSubLabel, rect.height);
                            var framesRect  = new Rect(rect.xMin + rect.width / 2, rect.yMin, rect.width / 2, rect.height);

                            if (readOnly)
                            {
                                EditorGUI.FloatField(secondsRect, Styles.SecondsPrefix, (float)time, EditorStyles.label);
                            }
                            else
                            {
                                time = DelayedAndDraggableDoubleField(secondsRect, Styles.SecondsPrefix, time, ref inputEvent);
                            }

                            if (frameRate > TimeUtility.kTimeEpsilon)
                            {
                                int    frames      = TimeUtility.ToFrames(time, frameRate);
                                double exactFrames = TimeUtility.ToExactFrames(time, frameRate);
                                bool   useIntField = TimeUtility.OnFrameBoundary(time, frameRate);
                                if (readOnly)
                                {
                                    if (useIntField)
                                    {
                                        EditorGUI.IntField(framesRect, Styles.FramesPrefix, frames, EditorStyles.label);
                                    }
                                    else
                                    {
                                        EditorGUI.FloatField(framesRect, Styles.FramesPrefix, (float)exactFrames, EditorStyles.label);
                                    }
                                }
                                else
                                {
                                    double newTime;
                                    EditorGUI.BeginChangeCheck();
                                    if (useIntField)
                                    {
                                        int newFrames = DelayedAndDraggableIntField(framesRect, Styles.FramesPrefix, frames, ref inputEvent);
                                        newTime = Math.Max(0, TimeUtility.FromFrames(newFrames, frameRate));
                                    }
                                    else
                                    {
                                        double newExactFrames = DelayedAndDraggableDoubleField(framesRect, Styles.FramesPrefix, exactFrames, ref inputEvent);
                                        newTime = Math.Max(0, TimeUtility.FromFrames((int)Math.Floor(newExactFrames), frameRate));
                                    }

                                    if (EditorGUI.EndChangeCheck())
                                    {
                                        time = newTime;
                                    }
                                }
                            }
                        }
            }

            return(Clamp(time, minValue, maxValue));
        }
Exemple #9
0
        public static double TimeField(GUIContent label, double time, bool readOnly, bool showMixed, double frameRate, double minValue, double maxValue)
        {
            Rect rect = EditorGUILayout.GetControlRect(new GUILayoutOption[0]);

            rect = EditorGUI.PrefixLabel(rect, label);
            int   indentLevel = EditorGUI.get_indentLevel();
            float labelWidth  = EditorGUIUtility.get_labelWidth();

            EditorGUI.set_indentLevel(0);
            EditorGUIUtility.set_labelWidth(13f);
            bool showMixedValue = EditorGUI.get_showMixedValue();

            EditorGUI.set_showMixedValue(showMixed);
            Rect rect2 = new Rect(rect.get_xMin(), rect.get_yMin(), rect.get_width() / 2f - 2f, rect.get_height());
            Rect rect3 = new Rect(rect.get_xMin() + rect.get_width() / 2f, rect.get_yMin(), rect.get_width() / 2f, rect.get_height());

            if (readOnly)
            {
                EditorGUI.FloatField(rect2, TimelineInspectorUtility.Styles.SecondsPrefix, (float)time, EditorStyles.get_label());
            }
            else
            {
                time = EditorGUI.DoubleField(rect2, TimelineInspectorUtility.Styles.SecondsPrefix, time);
            }
            if (frameRate > TimeUtility.kTimeEpsilon)
            {
                int    num  = TimeUtility.ToFrames(time, frameRate);
                double num2 = TimeUtility.ToExactFrames(time, frameRate);
                bool   flag = TimeUtility.OnFrameBoundary(time, frameRate);
                if (readOnly)
                {
                    if (flag)
                    {
                        EditorGUI.IntField(rect3, TimelineInspectorUtility.Styles.FramesPrefix, num, EditorStyles.get_label());
                    }
                    else
                    {
                        EditorGUI.FloatField(rect3, TimelineInspectorUtility.Styles.FramesPrefix, (float)num2, EditorStyles.get_label());
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    double num3;
                    if (flag)
                    {
                        int frames = EditorGUI.IntField(rect3, TimelineInspectorUtility.Styles.FramesPrefix, num);
                        num3 = Math.Max(0.0, TimeUtility.FromFrames(frames, frameRate));
                    }
                    else
                    {
                        double d = EditorGUI.DoubleField(rect3, TimelineInspectorUtility.Styles.FramesPrefix, num2);
                        num3 = Math.Max(0.0, TimeUtility.FromFrames((int)Math.Floor(d), frameRate));
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        time = num3;
                    }
                }
            }
            EditorGUI.set_showMixedValue(showMixedValue);
            EditorGUI.set_indentLevel(indentLevel);
            EditorGUIUtility.set_labelWidth(labelWidth);
            return(Math.Min(maxValue, Math.Max(minValue, time)));
        }
Exemple #10
0
        public static void TimeField(Rect rect, SerializedProperty property, GUIContent label, bool readOnly, double frameRate, double minValue, double maxValue)
        {
            GUIContent gUIContent = EditorGUI.BeginProperty(rect, label, property);

            rect = EditorGUI.PrefixLabel(rect, gUIContent);
            int   indentLevel = EditorGUI.get_indentLevel();
            float labelWidth  = EditorGUIUtility.get_labelWidth();

            EditorGUI.set_indentLevel(0);
            EditorGUIUtility.set_labelWidth(13f);
            EditorGUI.set_showMixedValue(property.get_hasMultipleDifferentValues());
            Rect rect2 = new Rect(rect.get_xMin(), rect.get_yMin(), rect.get_width() / 2f - 2f, rect.get_height());
            Rect rect3 = new Rect(rect.get_xMin() + rect.get_width() / 2f, rect.get_yMin(), rect.get_width() / 2f, rect.get_height());

            if (readOnly)
            {
                EditorGUI.FloatField(rect2, TimelineInspectorUtility.Styles.SecondsPrefix, (float)property.get_doubleValue(), EditorStyles.get_label());
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.PropertyField(rect2, property, TimelineInspectorUtility.Styles.SecondsPrefix);
                if (EditorGUI.EndChangeCheck())
                {
                    property.set_doubleValue(Math.Min(maxValue, Math.Max(minValue, property.get_doubleValue())));
                }
            }
            if (frameRate > TimeUtility.kTimeEpsilon)
            {
                EditorGUI.set_showMixedValue(property.get_hasMultipleDifferentValues());
                EditorGUI.BeginChangeCheck();
                double num  = property.get_doubleValue();
                int    num2 = TimeUtility.ToFrames(num, frameRate);
                double num3 = TimeUtility.ToExactFrames(num, frameRate);
                bool   flag = TimeUtility.OnFrameBoundary(num, frameRate);
                if (readOnly)
                {
                    if (flag)
                    {
                        EditorGUI.IntField(rect3, TimelineInspectorUtility.Styles.FramesPrefix, num2, EditorStyles.get_label());
                    }
                    else
                    {
                        EditorGUI.DoubleField(rect3, TimelineInspectorUtility.Styles.FramesPrefix, num3, EditorStyles.get_label());
                    }
                }
                else if (flag)
                {
                    int frames = EditorGUI.IntField(rect3, TimelineInspectorUtility.Styles.FramesPrefix, num2);
                    num = Math.Max(0.0, TimeUtility.FromFrames(frames, frameRate));
                }
                else
                {
                    double d = EditorGUI.DoubleField(rect3, TimelineInspectorUtility.Styles.FramesPrefix, num3);
                    num = Math.Max(0.0, TimeUtility.FromFrames((int)Math.Floor(d), frameRate));
                }
                if (EditorGUI.EndChangeCheck())
                {
                    property.set_doubleValue(Math.Min(maxValue, Math.Max(-maxValue, num)));
                }
            }
            EditorGUI.set_indentLevel(indentLevel);
            EditorGUIUtility.set_labelWidth(labelWidth);
            EditorGUI.EndProperty();
        }