Пример #1
0
        // Created editors for all the enabled extensions of this AudioSource.
        private void CreateExtensionEditors()
        {
            if (m_SpatializerEditor != null)
            {
                DestroyExtensionEditors();
            }

            System.Type spatializerEditorType = AudioExtensionManager.GetSourceSpatializerExtensionEditorType();
            m_SpatializerEditor = ScriptableObject.CreateInstance(spatializerEditorType) as AudioSourceExtensionEditor;

            if (m_SpatializerEditor != null)
            {
                for (int i = 0; i < targets.Length; i++)
                {
                    AudioSource source = targets[i] as AudioSource;
                    if (source != null)
                    {
                        Undo.RecordObject(source, "Add AudioSource extension properties");
                        string extensionName = AudioExtensionManager.GetSourceSpatializerExtensionType().Name;
                        for (int j = 0; j < m_SpatializerEditor.GetNumExtensionProperties(); j++)
                        {
                            PropertyName propertyName = m_SpatializerEditor.GetExtensionPropertyName(j);
                            float        value        = 0.0f;

                            // If the AudioSource is missing an extension property, then create it now.
                            if (!source.ReadExtensionProperty(extensionName, propertyName, ref value))
                            {
                                value = m_SpatializerEditor.GetExtensionPropertyDefaultValue(j);
                                source.WriteExtensionProperty(AudioExtensionManager.GetSourceSpatializerExtensionName(), extensionName, propertyName, value);
                            }
                        }
                    }
                }
            }

            m_AddSpatializerExtensionMixedValues = false;
        }
Пример #2
0
        public override void OnInspectorGUI()
        {
            InitStyles();
            serializedObject.Update();

            if (m_LowpassObject != null)
            {
                m_LowpassObject.Update();
            }

            HandleLowPassFilter();

            UpdateWrappersAndLegend();

            EditorGUILayout.PropertyField(m_AudioClip, ms_Styles.audioClipLabel);
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(m_OutputAudioMixerGroup, ms_Styles.outputMixerGroupLabel);
            EditorGUILayout.PropertyField(m_Mute);
            EditorGUILayout.PropertyField(m_BypassEffects);
            if (targets.Any(t => (t as AudioSource).outputAudioMixerGroup != null))
            {
                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUILayout.PropertyField(m_BypassListenerEffects);
                }
            }
            else
            {
                EditorGUILayout.PropertyField(m_BypassListenerEffects);
            }
            EditorGUILayout.PropertyField(m_BypassReverbZones);

            EditorGUILayout.PropertyField(m_PlayOnAwake);
            EditorGUILayout.PropertyField(m_Loop);

            EditorGUILayout.Space();
            EditorGUIUtility.sliderLabels.SetLabels(ms_Styles.priorityLeftLabel, ms_Styles.priorityRightLabel);
            EditorGUILayout.IntSlider(m_Priority, 0, 256, ms_Styles.priorityLabel);
            EditorGUIUtility.sliderLabels.SetLabels(null, null);
            EditorGUILayout.Space();
            EditorGUILayout.Slider(m_Volume, 0f, 1.0f, ms_Styles.volumeLabel);
            EditorGUILayout.Space();
            EditorGUILayout.Slider(m_Pitch, -3.0f, 3.0f, ms_Styles.pitchLabel);

            EditorGUILayout.Space();

            EditorGUIUtility.sliderLabels.SetLabels(ms_Styles.panLeftLabel, ms_Styles.panRightLabel);
            EditorGUILayout.Slider(m_Pan2D, -1f, 1f, ms_Styles.panStereoLabel);
            EditorGUIUtility.sliderLabels.SetLabels(null, null);
            EditorGUILayout.Space();

            // 3D Level control
            EditorGUIUtility.sliderLabels.SetLabels(ms_Styles.spatialLeftLabel, ms_Styles.spatialRightLabel);
            AnimProp(ms_Styles.spatialBlendLabel, m_AudioCurves[kSpatialBlendCurveID].curveProp, 0.0f, 1.0f, false);
            EditorGUIUtility.sliderLabels.SetLabels(null, null);
            EditorGUILayout.Space();

            // 3D Level control
            AnimProp(ms_Styles.reverbZoneMixLabel, m_AudioCurves[kReverbZoneMixCurveID].curveProp, 0.0f, 1.1f, false);
            EditorGUILayout.Space();

            m_Expanded3D = EditorGUILayout.Foldout(m_Expanded3D, "3D Sound Settings", true);
            if (m_Expanded3D)
            {
                EditorGUI.indentLevel++;
                Audio3DGUI();
                EditorGUI.indentLevel--;
            }

            if (AudioUtil.canUseSpatializerEffect)
            {
                EditorGUILayout.PropertyField(m_Spatialize, ms_Styles.spatializeLabel);
                if (m_Spatialize.boolValue && !m_Spatialize.hasMultipleDifferentValues)
                {
                    for (int i = 0; i < targets.Length; i++)
                    {
                        AudioSource          source    = targets[i] as AudioSource;
                        AudioSourceExtension extension = (source != null) ? AudioExtensionManager.GetSpatializerExtension(source) : null;

                        // If we are playing in Editor or previewing in the scene view, spatialize is true, and we do not have a spatializer extension, try to add one.
                        // We may have just toggled spatialize here in the Editor.
                        if ((source != null) && source.spatialize && source.isPlaying)
                        {
                            if (extension == null)
                            {
                                extension = AudioExtensionManager.AddSpatializerExtension(source);
                            }

                            AudioExtensionManager.GetReadyToPlay(extension);
                        }
                    }

                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(m_SpatializePostEffects, ms_Styles.spatializePostEffectsLabel);

                    bool allowExtensionEditing = (m_AddSpatializerExtension && !m_AddSpatializerExtensionMixedValues) || !serializedObject.isEditingMultipleObjects;
                    if (AudioExtensionManager.IsSourceSpatializerExtensionRegistered() && allowExtensionEditing)
                    {
                        EditorGUI.showMixedValue = m_AddSpatializerExtensionMixedValues;
                        bool addSpatializerExtensionNew = EditorGUILayout.Toggle(ms_Styles.addSpatializerExtensionLabel, m_AddSpatializerExtension);
                        EditorGUI.showMixedValue = false;

                        bool showExtensionProperties = false;
                        if (m_AddSpatializerExtension != addSpatializerExtensionNew)
                        {
                            m_AddSpatializerExtension = addSpatializerExtensionNew;
                            if (m_AddSpatializerExtension)
                            {
                                CreateExtensionEditors();

                                if (m_SpatializerEditor != null)
                                {
                                    showExtensionProperties = m_SpatializerEditor.FindAudioExtensionProperties(serializedObject);
                                }
                            }
                            else
                            {
                                ClearExtensionProperties();
                                DestroyExtensionEditors();
                                showExtensionProperties = false;
                            }
                        }
                        else if (m_SpatializerEditor != null)
                        {
                            showExtensionProperties = m_SpatializerEditor.FindAudioExtensionProperties(serializedObject);
                            if (!showExtensionProperties)
                            {
                                m_AddSpatializerExtension = false;
                                ClearExtensionProperties();
                                DestroyExtensionEditors();
                            }
                        }

                        if ((m_SpatializerEditor != null) && showExtensionProperties)
                        {
                            EditorGUI.indentLevel++;
                            m_SpatializerEditor.OnAudioSourceGUI();
                            EditorGUI.indentLevel--;

                            // Push any AudioSource extension property changes to the AudioSourceExtension properties. We always attempt to do this
                            // because we may be playing in Editor or previewing sound in the scene view.
                            for (int i = 0; i < targets.Length; i++)
                            {
                                AudioSource          source    = targets[i] as AudioSource;
                                AudioSourceExtension extension = (source != null) ? AudioExtensionManager.GetSpatializerExtension(source) : null;

                                if ((source != null) && (extension != null) && source.isPlaying)
                                {
                                    string extensionName = AudioExtensionManager.GetSourceSpatializerExtensionType().Name;
                                    for (int j = 0; j < m_SpatializerEditor.GetNumExtensionProperties(); j++)
                                    {
                                        PropertyName propertyName = m_SpatializerEditor.GetExtensionPropertyName(j);
                                        float        value        = 0.0f;
                                        if (source.ReadExtensionProperty(extensionName, propertyName, ref value))
                                        {
                                            extension.WriteExtensionProperty(propertyName, value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
            if (m_LowpassObject != null)
            {
                m_LowpassObject.ApplyModifiedProperties();
            }
        }