// Created editors for all the enabled extensions of this AudioSource.
        private void CreateExtensionEditors()
        {
            if (m_SpatializerEditor != null)
            {
                DestroyExtensionEditors();
            }

            System.Type spatializerEditorType = AudioExtensionManager.GetListenerSpatializerExtensionEditorType();
            m_SpatializerEditor = ScriptableObject.CreateInstance(spatializerEditorType) as AudioListenerExtensionEditor;

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

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

            m_AddSpatializerExtensionMixedValues = false;
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            bool allowExtensionEditing = (m_AddSpatializerExtension && !m_AddSpatializerExtensionMixedValues) || !serializedObject.isEditingMultipleObjects;

            if (AudioExtensionManager.IsListenerSpatializerExtensionRegistered() && allowExtensionEditing)
            {
                EditorGUI.showMixedValue = m_AddSpatializerExtensionMixedValues;
                bool addSpatializerExtensionNew = EditorGUILayout.Toggle(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.OnAudioListenerGUI();
                    EditorGUI.indentLevel--;

                    // Update AudioSourceExtension properties, if we are currently playing in Editor.
                    for (int i = 0; i < targets.Length; i++)
                    {
                        AudioListener listener = targets[i] as AudioListener;
                        if (listener != null)
                        {
                            AudioListenerExtension extension = AudioExtensionManager.GetSpatializerExtension(listener);
                            if (extension != null)
                            {
                                string extensionName = AudioExtensionManager.GetListenerSpatializerExtensionType().Name;
                                for (int j = 0; j < m_SpatializerEditor.GetNumExtensionProperties(); j++)
                                {
                                    PropertyName propertyName = m_SpatializerEditor.GetExtensionPropertyName(j);
                                    float        value        = 0.0f;
                                    if (listener.ReadExtensionProperty(extensionName, propertyName, ref value))
                                    {
                                        extension.WriteExtensionProperty(propertyName, value);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
        }