Esempio n. 1
0
        // Called by OnEnable to make sure the CurveEditor is not null,
        // and by Show so we get a fresh CurveEditor when the user clicks a new curve.
        void Init(CurveEditorSettings settings)
        {
            m_CurveEditor = new CurveEditor(GetCurveEditorRect(), GetCurveWrapperArray(), true);
            m_CurveEditor.curvesUpdated   = UpdateCurve;
            m_CurveEditor.scaleWithWindow = true;
            m_CurveEditor.margin          = 40;
            if (settings != null)
            {
                m_CurveEditor.settings = settings;
            }
            m_CurveEditor.settings.hTickLabelOffset   = 10;
            m_CurveEditor.settings.rectangleToolFlags = CurveEditorSettings.RectangleToolFlags.MiniRectangleTool;
            m_CurveEditor.settings.undoRedoSelection  = true;
            m_CurveEditor.settings.showWrapperPopups  = true;
            UpdateRegionDomain();

            // For each of horizontal and vertical axis, if we have a finite range for that axis, use that range,
            // otherwise use framing logic to determine shown range for that axis.
            bool frameH = true;
            bool frameV = true;

            if (!float.IsNegativeInfinity(m_CurveEditor.settings.hRangeMin) && !float.IsInfinity(m_CurveEditor.settings.hRangeMax))
            {
                m_CurveEditor.SetShownHRangeInsideMargins(m_CurveEditor.settings.hRangeMin, m_CurveEditor.settings.hRangeMax);
                frameH = false;
            }
            if (!float.IsNegativeInfinity(m_CurveEditor.settings.vRangeMin) && !float.IsInfinity(m_CurveEditor.settings.vRangeMax))
            {
                m_CurveEditor.SetShownVRangeInsideMargins(m_CurveEditor.settings.vRangeMin, m_CurveEditor.settings.vRangeMax);
                frameV = false;
            }

            m_CurveEditor.FrameSelected(frameH, frameV);
        }
        public void OnEnable(SerializedObject serializedObject)
        {
            m_WidthMultiplier = serializedObject.FindProperty("m_Parameters.widthMultiplier");
            m_WidthCurve      = serializedObject.FindProperty("m_Parameters.widthCurve");

            m_Settings.hRangeMin = 0.0f;
            m_Settings.vRangeMin = 0.0f;
            m_Settings.vRangeMax = 1.0f;
            m_Settings.hRangeMax = 1.0f;
            m_Settings.vSlider   = false;
            m_Settings.hSlider   = false;

            TickStyle hTS = new TickStyle();

            hTS.tickColor.color   = new Color(0.0f, 0.0f, 0.0f, 0.15f);
            hTS.distLabel         = 30;
            m_Settings.hTickStyle = hTS;
            TickStyle vTS = new TickStyle();

            vTS.tickColor.color   = new Color(0.0f, 0.0f, 0.0f, 0.15f);
            vTS.distLabel         = 20;
            m_Settings.vTickStyle = vTS;

            m_Settings.undoRedoSelection = true;

            m_Editor          = new CurveEditor(new Rect(0, 0, 1000, 100), new CurveWrapper[0], false);
            m_Editor.settings = m_Settings;
            m_Editor.margin   = 25;
            m_Editor.SetShownHRangeInsideMargins(0.0f, 1.0f);
            m_Editor.SetShownVRangeInsideMargins(0.0f, 1.0f);
            m_Editor.ignoreScrollWheelUntilClicked = true;

            Undo.undoRedoPerformed += UndoRedoPerformed;
        }
Esempio n. 3
0
        public void DrawCurveEditor(Rect rect, WindowState state, Vector2 clipRange, bool loop, bool selected)
        {
            var timelineWidth = state.TimeToPixel(Mathf.Max((float)state.editSequence.duration, state.timeAreaShownRange.y));

            m_CurveEditor.rect = new Rect(-rect.xMin, 0.0f, timelineWidth, rect.height);
            UpdateCurveEditorIfNeeded(state);

            var curveEndTime = m_DataSource.start + m_DataSource.animationClip.length / m_DataSource.timeScale;
            var curveRange   = new Vector2(state.TimeToPixel(m_DataSource.start), state.TimeToPixel(curveEndTime));

            m_CurveEditor.leftmargin  = curveRange.x;
            m_CurveEditor.rightmargin = timelineWidth - curveRange.y;
            m_CurveEditor.topmargin   = m_CurveEditor.bottommargin = CalculateTopMargin(rect.height);
            m_CurveEditor.SetShownHRangeInsideMargins(0.0f, m_DataSource.animationClip.length); //align the curve with the clip.

            if (m_LastFrameRate != state.referenceSequence.frameRate)
            {
                m_CurveEditor.hTicks.SetTickModulosForFrameRate(state.referenceSequence.frameRate);
                m_LastFrameRate = state.referenceSequence.frameRate;
            }

            foreach (var cw in m_CurveEditor.animationCurves)
            {
                cw.renderer.SetWrap(WrapMode.Default, loop ? WrapMode.Loop : WrapMode.Default);
            }

            using (new GUIGroupScope(rect))
            {
                var localRect       = new Rect(0.0f, 0.0f, rect.width, rect.height);
                var localClipRange  = new Vector2(Mathf.Floor(clipRange.x - rect.xMin), Mathf.Ceil(clipRange.y - rect.xMin));
                var localCurveRange = new Vector2(Mathf.Floor(curveRange.x - rect.xMin), Mathf.Ceil(curveRange.y - rect.xMin));

                EditorGUI.DrawRect(new Rect(localCurveRange.x, 0.0f, 1.0f, rect.height), new Color(1.0f, 1.0f, 1.0f, 0.5f));
                DrawCurveEditorBackground(localRect, localClipRange);

                if (selected)
                {
                    var selectionRect = new Rect(localClipRange.x, 0.0f, localClipRange.y - localClipRange.x, localRect.height);
                    DrawOutline(selectionRect);
                }

                EditorGUI.BeginChangeCheck();
                {
                    var evt = Event.current;
                    if (evt.type == EventType.Layout || evt.type == EventType.Repaint || selected)
                    {
                        m_CurveEditor.CurveGUI();
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    OnCurvesUpdated();
                }

                DrawOverlay(localRect, localClipRange, DirectorStyles.Instance.customSkin.colorInlineCurveOutOfRangeOverlay);
                DrawGrid(localRect, localCurveRange);
            }
        }
        public void DrawCurveEditor(Rect rect, WindowState state, Vector2 clipRange, bool loop, bool selected)
        {
            SetupMarginsAndRect(rect, state);
            UpdateCurveEditorIfNeeded(state);

            if (m_ShouldRestoreShownArea)
            {
                RestoreShownArea();
            }

            var curveVisibleTimeRange = CalculateCurveVisibleTimeRange(state.timeAreaShownRange, m_DataSource);

            m_CurveEditor.SetShownHRangeInsideMargins(curveVisibleTimeRange.x, curveVisibleTimeRange.y); //align the curve with the clip.

            if (m_LastFrameRate != state.referenceSequence.frameRate)
            {
                m_CurveEditor.hTicks.SetTickModulosForFrameRate(state.referenceSequence.frameRate);
                m_LastFrameRate = state.referenceSequence.frameRate;
            }

            foreach (var cw in m_CurveEditor.animationCurves)
            {
                cw.renderer.SetWrap(WrapMode.Default, loop ? WrapMode.Loop : WrapMode.Default);
            }

            using (new GUIGroupScope(rect))
            {
                var localRect      = new Rect(0.0f, 0.0f, rect.width, rect.height);
                var localClipRange = new Vector2(Mathf.Floor(clipRange.x - rect.xMin), Mathf.Ceil(clipRange.y - rect.xMin));
                var curveStartPosX = Mathf.Floor(state.TimeToPixel(m_DataSource.start) - rect.xMin);

                EditorGUI.DrawRect(new Rect(curveStartPosX, 0.0f, 1.0f, rect.height), new Color(1.0f, 1.0f, 1.0f, 0.5f));
                DrawCurveEditorBackground(localRect);

                if (selected)
                {
                    var selectionRect = new Rect(localClipRange.x, 0.0f, localClipRange.y - localClipRange.x, localRect.height);
                    DrawOutline(selectionRect);
                }

                EditorGUI.BeginChangeCheck();
                {
                    var evt = Event.current;
                    if (evt.type == EventType.Layout || evt.type == EventType.Repaint || selected)
                    {
                        m_CurveEditor.CurveGUI();
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    OnCurvesUpdated();
                }

                DrawOverlay(localRect, localClipRange, DirectorStyles.Instance.customSkin.colorInlineCurveOutOfRangeOverlay);
                DrawGrid(localRect, curveStartPosX);
            }
        }
        // Called by OnEnable to make sure the CurveEditor is not null,
        // and by Show so we get a fresh CurveEditor when the user clicks a new curve.
        void Init(CurveEditorSettings settings)
        {
            m_CurveEditor = new CurveEditor(GetCurveEditorRect(), GetCurveWrapperArray(), true);
            m_CurveEditor.curvesUpdated   = UpdateCurve;
            m_CurveEditor.scaleWithWindow = true;
            m_CurveEditor.margin          = 40;
            if (settings != null)
            {
                m_CurveEditor.settings = settings;
            }
            m_CurveEditor.settings.hTickLabelOffset   = 10;
            m_CurveEditor.settings.rectangleToolFlags = CurveEditorSettings.RectangleToolFlags.MiniRectangleTool;

            // As there is no guarantee animation curve changes are recorded in undo redo, we can't really
            // handle curve selection in undo redo either.
            m_CurveEditor.settings.undoRedoSelection = false;
            m_CurveEditor.settings.showWrapperPopups = true;

            // For each of horizontal and vertical axis, if we have a finite range for that axis, use that range,
            // otherwise use framing logic to determine shown range for that axis.
            bool frameH = true;
            bool frameV = true;

            if (m_CurveEditor.settings.hRangeMin != Mathf.NegativeInfinity && m_CurveEditor.settings.hRangeMax != Mathf.Infinity)
            {
                m_CurveEditor.SetShownHRangeInsideMargins(m_CurveEditor.settings.hRangeMin, m_CurveEditor.settings.hRangeMax);
                frameH = false;
            }
            if (m_CurveEditor.settings.vRangeMin != Mathf.NegativeInfinity && m_CurveEditor.settings.vRangeMax != Mathf.Infinity)
            {
                m_CurveEditor.SetShownVRangeInsideMargins(m_CurveEditor.settings.vRangeMin, m_CurveEditor.settings.vRangeMax);
                frameV = false;
            }

            m_CurveEditor.FrameSelected(frameH, frameV);

            titleContent = EditorGUIUtility.TrTextContent("Curve");

            // deal with window size
            minSize = new Vector2(240, 240 + kPresetsHeight);
            maxSize = new Vector2(10000, 10000);
        }
    public void Init()
    {
        if (m_AddedCurves != null)
        {
            return;
        }

        m_AddedCurves = new List <CurveData>();

        // Colors
        m_Colors = new Color[]
        {
            new Color(255 / 255f, 158 / 255f, 33 / 255f),               // orange
            new Color(223 / 255f, 54 / 255f, 148 / 255f),               // purple
            new Color(0f, 175 / 255f, 255 / 255f),                      // blue
            new Color(255 / 255f, 235 / 255f, 0),                       // yellow
            new Color(50 / 255f, 255 / 255f, 68 / 255f),                // green
            new Color(250 / 255f, 0f, 0f),                              // red  (this is the first color used)
        };
        m_AvailableColors = new List <Color>(m_Colors);

        // Curve Editor
        m_CurveEditorSettings.useFocusColors                = true;
        m_CurveEditorSettings.showAxisLabels                = false;
        m_CurveEditorSettings.hRangeMin                     = 0.0f;
        m_CurveEditorSettings.vRangeMin                     = 0.0F;
        m_CurveEditorSettings.vRangeMax                     = 1.0f;
        m_CurveEditorSettings.hRangeMax                     = 1.0F;
        m_CurveEditorSettings.vSlider                       = false;
        m_CurveEditorSettings.hSlider                       = false;
        m_CurveEditorSettings.showWrapperPopups             = true;
        m_CurveEditorSettings.rectangleToolFlags            = CurveEditorSettings.RectangleToolFlags.MiniRectangleTool;
        m_CurveEditorSettings.hTickLabelOffset              = 5;
        m_CurveEditorSettings.allowDraggingCurvesAndRegions = true;
        m_CurveEditorSettings.allowDeleteLastKeyInCurve     = false;

        TickStyle hTS = new TickStyle();

        hTS.tickColor.color = new Color(0.0f, 0.0f, 0.0f, 0.2f);
        hTS.distLabel       = 30;
        hTS.stubs           = false;
        hTS.centerLabel     = true;
        m_CurveEditorSettings.hTickStyle = hTS;

        TickStyle vTS = new TickStyle();

        vTS.tickColor.color = new Color(0.0f, 0.0f, 0.0f, 0.2f);
        vTS.distLabel       = 20;
        vTS.stubs           = false;
        vTS.centerLabel     = true;
        m_CurveEditorSettings.vTickStyle = vTS;

        m_CurveEditor             = new CurveEditor(new Rect(0, 0, 1000, 100), CreateCurveWrapperArray(), false);
        m_CurveEditor.settings    = m_CurveEditorSettings;
        m_CurveEditor.leftmargin  = 40;
        m_CurveEditor.rightmargin = m_CurveEditor.topmargin = m_CurveEditor.bottommargin = 25;
        m_CurveEditor.SetShownHRangeInsideMargins(m_CurveEditorSettings.hRangeMin, m_CurveEditorSettings.hRangeMax);
        m_CurveEditor.SetShownVRangeInsideMargins(m_CurveEditorSettings.vRangeMin, m_CurveEditorSettings.hRangeMax);
        m_CurveEditor.ignoreScrollWheelUntilClicked = false;

        Undo.undoRedoPerformed += UndoRedoPerformed;
    }
Esempio n. 7
0
        public void DrawCurveEditor(Rect animEditorRect, WindowState state, Vector2 activeRange, bool loop, bool selected)
        {
            var curveStart    = state.TimeToPixel(m_DataSource.start);
            var minCurveStart = animEditorRect.xMax - 1.0f;

            if (curveStart > minCurveStart) // Prevent the curve from drawing inside small rect
            {
                animEditorRect.xMax += curveStart - minCurveStart;
            }

            UpdateCurveEditorIfNeeded(state);

            DrawCurveEditorBackground(animEditorRect);

            float localCurveStart = curveStart - animEditorRect.xMin;

            // adjust the top margin so smaller rectangle have smaller top / bottom margins.
            m_CurveEditor.topmargin = m_CurveEditor.bottommargin = CalculateTopMargin(animEditorRect.height);
            // calculate the margin needed to align the curve with the clip.
            m_CurveEditor.rightmargin = 0.0f;
            m_CurveEditor.leftmargin  = localCurveStart;

            m_CurveEditor.rect = new Rect(0.0f, 0.0f, animEditorRect.width, animEditorRect.height);

            m_CurveEditor.SetShownHRangeInsideMargins(0.0f, (state.PixelToTime(animEditorRect.xMax) - m_DataSource.start) * m_DataSource.timeScale);

            if (m_LastFrameRate != state.referenceSequence.frameRate)
            {
                m_CurveEditor.hTicks.SetTickModulosForFrameRate(state.referenceSequence.frameRate);
                m_LastFrameRate = state.referenceSequence.frameRate;
            }

            foreach (CurveWrapper cw in m_CurveEditor.animationCurves)
            {
                cw.renderer.SetWrap(WrapMode.Default, loop ? WrapMode.Loop : WrapMode.Default);
            }

            m_CurveEditor.BeginViewGUI();

            Color oldColor = GUI.color;

            GUI.color = Color.white;

            GUI.BeginGroup(animEditorRect);

            // Draw a line at 0
            Graphics.DrawLine(new Vector2(localCurveStart, 0.0f), new Vector2(localCurveStart, animEditorRect.height), new Color(1.0f, 1.0f, 1.0f, 0.5f));

            float rangeStart = activeRange.x - animEditorRect.x;
            float rangeWidth = activeRange.y - activeRange.x;

            // draw selection outline underneath the curves.
            if (selected)
            {
                var selectionRect = new Rect(rangeStart, 0.0f, rangeWidth, animEditorRect.height);
                DrawOutline(selectionRect);
            }

            EditorGUI.BeginChangeCheck();

            Event evt = Event.current;

            if ((evt.type == EventType.Layout) || (evt.type == EventType.Repaint) || selected)
            {
                m_CurveEditor.CurveGUI();
            }

            m_CurveEditor.EndViewGUI();

            if (EditorGUI.EndChangeCheck())
            {
                OnCurvesUpdated();
            }

            // draw overlays on top of curves
            var overlayColor = DirectorStyles.Instance.customSkin.colorInlineCurveOutOfRangeOverlay;

            var leftSide = new Rect(localCurveStart, 0.0f, rangeStart - localCurveStart, animEditorRect.height);

            EditorGUI.DrawRect(leftSide, overlayColor);

            var rightSide = new Rect(rangeStart + rangeWidth, 0.0f, animEditorRect.width - rangeStart - rangeWidth, animEditorRect.height);

            EditorGUI.DrawRect(rightSide, overlayColor);

            GUI.color = oldColor;

            GUI.EndGroup();

            // draw the grid labels last
            Rect gridRect = animEditorRect;

            gridRect.width = s_GridLabelWidth;
            float offset = localCurveStart - s_GridLabelWidth;

            if (offset > 0.0f)
            {
                gridRect.x = animEditorRect.x + offset;
            }

            GUI.BeginGroup(gridRect);

            m_CurveEditor.GridGUI();

            GUI.EndGroup();
        }
Esempio n. 8
0
        void OnEnable()
        {
            m_AudioClip             = serializedObject.FindProperty("m_audioClip");
            m_PlayOnAwake           = serializedObject.FindProperty("m_PlayOnAwake");
            m_Volume                = serializedObject.FindProperty("m_Volume");
            m_Pitch                 = serializedObject.FindProperty("m_Pitch");
            m_Loop                  = serializedObject.FindProperty("Loop");
            m_Mute                  = serializedObject.FindProperty("Mute");
            m_Spatialize            = serializedObject.FindProperty("Spatialize");
            m_SpatializePostEffects = serializedObject.FindProperty("SpatializePostEffects");
            m_Priority              = serializedObject.FindProperty("Priority");
            m_DopplerLevel          = serializedObject.FindProperty("DopplerLevel");
            m_MinDistance           = serializedObject.FindProperty("MinDistance");
            m_MaxDistance           = serializedObject.FindProperty("MaxDistance");
            m_Pan2D                 = serializedObject.FindProperty("Pan2D");
            m_RolloffMode           = serializedObject.FindProperty("rolloffMode");
            m_BypassEffects         = serializedObject.FindProperty("BypassEffects");
            m_BypassListenerEffects = serializedObject.FindProperty("BypassListenerEffects");
            m_BypassReverbZones     = serializedObject.FindProperty("BypassReverbZones");
            m_OutputAudioMixerGroup = serializedObject.FindProperty("OutputAudioMixerGroup");

            m_AudioCurves = new AudioCurveWrapper[]
            {
                new AudioCurveWrapper(AudioCurveType.Volume, "Volume", kRolloffCurveID, kRolloffCurveColor, serializedObject.FindProperty("rolloffCustomCurve"), 0, 1),
                new AudioCurveWrapper(AudioCurveType.SpatialBlend, "Spatial Blend", kSpatialBlendCurveID, kSpatialCurveColor, serializedObject.FindProperty("panLevelCustomCurve"), 0, 1),
                new AudioCurveWrapper(AudioCurveType.Spread, "Spread", kSpreadCurveID, kSpreadCurveColor, serializedObject.FindProperty("spreadCustomCurve"), 0, 1),
                new AudioCurveWrapper(AudioCurveType.Lowpass, "Low-Pass", kLowPassCurveID, kLowPassCurveColor, null, 0, 1),
                new AudioCurveWrapper(AudioCurveType.ReverbZoneMix, "Reverb Zone Mix", kReverbZoneMixCurveID, kReverbZoneMixCurveColor, serializedObject.FindProperty("reverbZoneMixCustomCurve"), 0, 1.1f)
            };

            m_CurveEditorSettings.hRangeMin = 0.0f;
            m_CurveEditorSettings.vRangeMin = 0.0f;
            m_CurveEditorSettings.vRangeMax = 1.1f;
            m_CurveEditorSettings.hRangeMax = 1.0f;
            m_CurveEditorSettings.vSlider   = false;
            m_CurveEditorSettings.hSlider   = false;

            TickStyle hTS = new TickStyle();

            hTS.tickColor.color = new Color(0.0f, 0.0f, 0.0f, 0.15f);
            hTS.distLabel       = 30;
            m_CurveEditorSettings.hTickStyle = hTS;
            TickStyle vTS = new TickStyle();

            vTS.tickColor.color = new Color(0.0f, 0.0f, 0.0f, 0.15f);
            vTS.distLabel       = 20;
            m_CurveEditorSettings.vTickStyle = vTS;

            m_CurveEditorSettings.undoRedoSelection = true;

            m_CurveEditor          = new CurveEditor(new Rect(0, 0, 1000, 100), new CurveWrapper[0], false);
            m_CurveEditor.settings = m_CurveEditorSettings;
            m_CurveEditor.margin   = 25;
            m_CurveEditor.SetShownHRangeInsideMargins(0.0f, 1.0f);
            m_CurveEditor.SetShownVRangeInsideMargins(0.0f, 1.1f);
            m_CurveEditor.ignoreScrollWheelUntilClicked = true;

            m_LastSourcePosition      = GetSourcePos(target);
            m_LastListenerPosition    = AudioUtil.GetListenerPos();
            EditorApplication.update += Update;

            m_Expanded3D = EditorPrefs.GetBool("AudioSourceExpanded3D", m_Expanded3D);
        }