public static double FrameRateField(double frameRate, GUIContent label, Rect position, out bool isValid)
        {
            double    frameRateDouble = FrameRateDisplayUtility.RoundFrameRate(frameRate);
            FrameRate frameRateObj    = TimeUtility.GetClosestFrameRate(frameRateDouble);

            isValid = frameRateObj.IsValid();
            TimeUtility.ToStandardFrameRate(frameRateObj, out StandardFrameRates option);

            position = EditorGUI.PrefixLabel(position, label);
            Rect posPopup      = new Rect(position.x, position.y, position.width / 2, position.height);
            Rect posFloatField = new Rect(posPopup.xMax, position.y, position.width / 2, position.height);

            using (var checkOption = new EditorGUI.ChangeCheckScope())
            {
                option = (StandardFrameRates)EditorGUI.Popup(posPopup, (int)option,
                                                             FrameRateDisplayUtility.GetDefaultFrameRatesLabels(option));

                if (checkOption.changed)
                {
                    isValid = true;
                    return(TimeUtility.ToFrameRate(option).rate);
                }
            }

            using (var checkFrame = new EditorGUI.ChangeCheckScope())
            {
                frameRateDouble = Math.Abs(EditorGUI.DoubleField(posFloatField, frameRateDouble));
                frameRateObj    = TimeUtility.GetClosestFrameRate(frameRateDouble);
                if (checkFrame.changed)
                {
                    isValid = frameRateObj.IsValid();
                    return(isValid ? frameRateObj.rate : frameRateDouble);
                }
            }

            return(frameRateDouble);
        }
Example #2
0
        void AddStandardFrameRateMenu(GenericMenu menu, StandardFrameRates option, string label, bool on)
        {
            var gui = EditorGUIUtility.TextContent(String.Format(k_FrameRateMenuLabel, label));

            if (state.editSequence.isReadOnly)
            {
                menu.AddDisabledItem(gui, on);
                return;
            }

            FrameRate value = TimeUtility.ToFrameRate(option);

            if (!value.IsValid())
            {
                menu.AddItem(gui, true, () => { });
            }
            else
            {
                menu.AddItem(gui, on, r =>
                {
                    state.editSequence.frameRate = (float)value.rate;
                }, value);
            }
        }