Example #1
0
        void InitCurvePresets()
        {
            if (m_CurvePresets == null)
            {
                AnimationCurve max = m_CurveEditor.animationCurves[0].curve;
                AnimationCurve min = m_CurveEditor.animationCurves.Length > 1 ? m_CurveEditor.animationCurves[1].curve : null;

                // Selection callback for library window
                System.Action <DoubleCurve> presetSelectedCallback = delegate(DoubleCurve presetCurve)
                {
                    var doubleCurve = new DoubleCurve(min, max, true);
                    doubleCurve.minCurve.keys         = CurveEditorWindow.GetNormalizedKeys(presetCurve.minCurve.keys, m_CurveEditor);
                    doubleCurve.minCurve.postWrapMode = presetCurve.minCurve.postWrapMode;
                    doubleCurve.minCurve.preWrapMode  = presetCurve.minCurve.preWrapMode;

                    doubleCurve.maxCurve.keys         = CurveEditorWindow.GetNormalizedKeys(presetCurve.maxCurve.keys, m_CurveEditor);
                    doubleCurve.maxCurve.postWrapMode = presetCurve.maxCurve.postWrapMode;
                    doubleCurve.maxCurve.preWrapMode  = presetCurve.maxCurve.preWrapMode;

                    m_CurveEditor.SelectNone();
                    RefreshShownCurves();
                    SendEvent("CurveChanged", true);
                };

                // We set the curve to save when showing the popup to ensure to scale the current state of the curve
                m_CurvePresets = new DoubleCurvePresetsContentsForPopupWindow(new DoubleCurve(min, max, true), presetSelectedCallback);
                m_CurvePresets.InitIfNeeded();
                m_CurvePresets.GetPresetLibraryEditor().GetCurrentLib().useRanges = false;
            }
        }
Example #2
0
        void DrawPresetSwatchArea()
        {
            GUI.Box(new Rect(0, position.height - k_PresetsHeight, position.width, k_PresetsHeight), "", s_Styles.curveSwatchArea);
            Color curveColor = m_Color;

            curveColor.a *= 0.6f;
            float yPos = position.height - k_PresetsHeight + (k_PresetsHeight - k_PresetSwatchHeight) * 0.5f;

            InitCurvePresets();
            var curveLibrary = m_CurvePresets.GetPresetLibraryEditor().GetCurrentLib();

            if (curveLibrary != null)
            {
                GUIContent guiContent = EditorGUIUtility.TempContent(string.Empty);
                for (int i = 0; i < curveLibrary.Count(); i++)
                {
                    Rect swatchRect = new Rect(k_PresetSwatchMargin + (k_PresetSwatchWidth + k_PresetSwatchSeperation) * i, yPos, k_PresetSwatchWidth, k_PresetSwatchHeight);
                    guiContent.tooltip = curveLibrary.GetName(i);
                    if (GUI.Button(swatchRect, guiContent, s_Styles.curveSwatch))
                    {
                        AnimationCurve max       = m_CurveEditor.animationCurves[0].curve;
                        AnimationCurve min       = m_CurveEditor.animationCurves.Length > 1 ? m_CurveEditor.animationCurves[1].curve : null;
                        var            animCurve = curveLibrary.GetPreset(i) as DoubleCurve;

                        max.keys         = CurveEditorWindow.GetDenormalizedKeys(animCurve.maxCurve.keys, m_CurveEditor);
                        max.postWrapMode = animCurve.maxCurve.postWrapMode;
                        max.preWrapMode  = animCurve.maxCurve.preWrapMode;

                        if (min != null)
                        {
                            min.keys         = CurveEditorWindow.GetDenormalizedKeys(animCurve.minCurve.keys, m_CurveEditor);
                            min.postWrapMode = animCurve.minCurve.postWrapMode;
                            min.preWrapMode  = animCurve.minCurve.preWrapMode;
                        }

                        m_CurveEditor.SelectNone();
                        RefreshShownCurves();
                        SendEvent("CurveChanged", true);
                    }
                    if (Event.current.type == EventType.Repaint)
                    {
                        curveLibrary.Draw(swatchRect, i);
                    }

                    if (swatchRect.xMax > position.width - 2 * k_PresetSwatchMargin)
                    {
                        break;
                    }
                }
            }

            // Dropdown
            Rect presetDropDownButtonRect = new Rect(k_PresetSwatchMargin - k_PresetsDropdownButtonSize, yPos + k_PresetSwatchSeperation, k_PresetsDropdownButtonSize, k_PresetsDropdownButtonSize);

            if (EditorGUI.DropdownButton(presetDropDownButtonRect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive, EditorStyles.inspectorTitlebarText))
            {
                if (m_MaxCurve != null)
                {
                    AnimationCurve max     = m_CurveEditor.animationCurves[0].curve;
                    AnimationCurve maxCopy = new AnimationCurve(CurveEditorWindow.GetNormalizedKeys(max.keys, m_CurveEditor));
                    maxCopy.postWrapMode = max.postWrapMode;
                    maxCopy.preWrapMode  = max.preWrapMode;

                    AnimationCurve minCopy = null;
                    if (m_MinCurve != null)
                    {
                        AnimationCurve min = m_CurveEditor.animationCurves[1].curve;
                        minCopy = new AnimationCurve(CurveEditorWindow.GetNormalizedKeys(min.keys, m_CurveEditor));
                        minCopy.postWrapMode = min.postWrapMode;
                        minCopy.preWrapMode  = min.preWrapMode;
                    }

                    m_CurvePresets.doubleCurveToSave = new DoubleCurve(minCopy, maxCopy, true);
                    PopupWindow.Show(presetDropDownButtonRect, m_CurvePresets);
                }
            }
        }