void OnGUI()
        {
            bool gotMouseUp = (Event.current.type == EventType.MouseUp);

            if (delegateView == null && m_OnCurveChanged == null)
            {
                m_Curve = null;
            }

            if (ms_Styles == null)
            {
                ms_Styles = new Styles();
            }

            // Curve Editor
            m_CurveEditor.rect         = GetCurveEditorRect();
            m_CurveEditor.hRangeLocked = Event.current.shift;
            m_CurveEditor.vRangeLocked = EditorGUI.actionKey;

            GUI.changed = false;

            GUI.Label(m_CurveEditor.drawRect, GUIContent.none, ms_Styles.curveEditorBackground);
            m_CurveEditor.OnGUI();

            // Preset swatch area
            GUI.Box(new Rect(0, position.height - kPresetsHeight, position.width, kPresetsHeight), "", ms_Styles.curveSwatchArea);
            Color curveColor = m_Color;

            curveColor.a *= 0.6f;
            const float margin = 45f;
            const float width  = 40f;
            const float height = 25f;
            float       yPos   = position.height - kPresetsHeight + (kPresetsHeight - height) * 0.5f;

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

            if (curveLibrary != null)
            {
                for (int i = 0; i < curveLibrary.Count(); i++)
                {
                    Rect swatchRect = new Rect(margin + (width + 5f) * i, yPos, width, height);
                    m_GUIContent.tooltip = curveLibrary.GetName(i);
                    if (GUI.Button(swatchRect, m_GUIContent, ms_Styles.curveSwatch))
                    {
                        AnimationCurve animCurve = curveLibrary.GetPreset(i) as AnimationCurve;
                        m_Curve.keys         = GetDenormalizedKeys(animCurve.keys);
                        m_Curve.postWrapMode = animCurve.postWrapMode;
                        m_Curve.preWrapMode  = animCurve.preWrapMode;
                        m_CurveEditor.SelectNone();
                        SendEvent(CurveChangedCommand, true);
                    }
                    if (Event.current.type == EventType.Repaint)
                    {
                        curveLibrary.Draw(swatchRect, i);
                    }

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

            Rect presetDropDownButtonRect = new Rect(margin - 20f, yPos + 5f, 20, 20);

            PresetDropDown(presetDropDownButtonRect);

            // For adding default preset curves
            //if (EditorGUI.DropdownButton(new Rect (position.width -26, yPos, 20, 20), GUIContent.none, FocusType.Passive, "OL Plus"))
            //  AddDefaultPresetsToCurrentLib ();

            if (Event.current.type == EventType.Used && gotMouseUp)
            {
                DoUpdateCurve(false);
                SendEvent(CurveChangeCompletedCommand, true);
            }
            else if (Event.current.type != EventType.Layout && Event.current.type != EventType.Repaint)
            {
                DoUpdateCurve(true);
            }
        }
Esempio n. 2
0
        private void Audio3DGUI()
        {
            EditorGUILayout.Slider(m_DopplerLevel, 0.0f, 5.0f, ms_Styles.dopplerLevelLabel);

            // Spread control
            AnimProp(ms_Styles.spreadLabel, m_AudioCurves[kSpreadCurveID].curveProp, 0.0f, 360.0f, true);

            // Rolloff mode
            if (m_RolloffMode.hasMultipleDifferentValues ||
                (m_RolloffMode.enumValueIndex == (int)AudioRolloffMode.Custom && m_AudioCurves[kRolloffCurveID].curveProp.hasMultipleDifferentValues)
                )
            {
                EditorGUILayout.TargetChoiceField(m_AudioCurves[kRolloffCurveID].curveProp, ms_Styles.rolloffLabel, SetRolloffToTarget);
            }
            else
            {
                EditorGUILayout.PropertyField(m_RolloffMode, ms_Styles.rolloffLabel);

                if ((AudioRolloffMode)m_RolloffMode.enumValueIndex != AudioRolloffMode.Custom)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(m_MinDistance);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_MinDistance.floatValue = Mathf.Clamp(m_MinDistance.floatValue, 0, m_MaxDistance.floatValue / 1.01f);
                    }
                }
                else
                {
                    using (new EditorGUI.DisabledScope(true))
                    {
                        EditorGUILayout.LabelField(m_MinDistance.displayName, ms_Styles.controlledByCurveLabel);
                    }
                }
            }

            // Max distance control
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_MaxDistance);
            if (EditorGUI.EndChangeCheck())
            {
                m_MaxDistance.floatValue = Mathf.Min(Mathf.Max(Mathf.Max(m_MaxDistance.floatValue, 0.01f), m_MinDistance.floatValue * 1.01f), 1000000.0f);
            }

            Rect r = GUILayoutUtility.GetAspectRect(1.333f, GUI.skin.textField);

            r.xMin += EditorGUI.indent;
            if (Event.current.type != EventType.Layout && Event.current.type != EventType.Used)
            {
                m_CurveEditor.rect = new Rect(r.x, r.y, r.width, r.height);
            }

            // Draw Curve Editor
            UpdateWrappersAndLegend();
            GUI.Label(m_CurveEditor.drawRect, GUIContent.none, "TextField");

            m_CurveEditor.hRangeLocked = Event.current.shift;
            m_CurveEditor.vRangeLocked = EditorGUI.actionKey;

            m_CurveEditor.OnGUI();

            // Draw current listener position
            if (targets.Length == 1)
            {
                AudioSource   t             = (AudioSource)target;
                AudioListener audioListener = (AudioListener)FindObjectOfType(typeof(AudioListener));
                if (audioListener != null)
                {
                    float distToListener = (AudioUtil.GetListenerPos() - t.transform.position).magnitude;
                    DrawLabel("Listener", distToListener, r);
                }
            }

            // Draw legend
            DrawLegend();

            if (!m_CurveEditor.InLiveEdit())
            {
                // Check if any of the curves changed
                foreach (AudioCurveWrapper audioCurve in m_AudioCurves)
                {
                    if ((m_CurveEditor.GetCurveWrapperFromID(audioCurve.id) != null) && (m_CurveEditor.GetCurveWrapperFromID(audioCurve.id).changed))
                    {
                        AnimationCurve changedCurve = m_CurveEditor.GetCurveWrapperFromID(audioCurve.id).curve;

                        // Never save a curve with no keys
                        if (changedCurve.length > 0)
                        {
                            audioCurve.curveProp.animationCurveValue = changedCurve;
                            m_CurveEditor.GetCurveWrapperFromID(audioCurve.id).changed = false;

                            // Volume curve special handling
                            if (audioCurve.type == AudioCurveType.Volume)
                            {
                                m_RolloffMode.enumValueIndex = (int)AudioRolloffMode.Custom;
                            }
                        }
                    }
                }
            }
        }