Ejemplo n.º 1
0
        private void CreateExtensionEditors()
        {
            if (this.m_SpatializerEditor != null)
            {
                this.DestroyExtensionEditors();
            }
            Type listenerSpatializerExtensionEditorType = AudioExtensionManager.GetListenerSpatializerExtensionEditorType();

            this.m_SpatializerEditor = (ScriptableObject.CreateInstance(listenerSpatializerExtensionEditorType) as AudioListenerExtensionEditor);
            if (this.m_SpatializerEditor != null)
            {
                for (int i = 0; i < base.targets.Length; i++)
                {
                    AudioListener audioListener = base.targets[i] as AudioListener;
                    if (audioListener != null)
                    {
                        Undo.RecordObject(audioListener, "Add AudioListener extension properties");
                        PropertyName listenerSpatializerExtensionName = AudioExtensionManager.GetListenerSpatializerExtensionName();
                        for (int j = 0; j < this.m_SpatializerEditor.GetNumExtensionProperties(); j++)
                        {
                            PropertyName extensionPropertyName = this.m_SpatializerEditor.GetExtensionPropertyName(j);
                            float        propertyValue         = 0f;
                            if (!audioListener.ReadExtensionProperty(listenerSpatializerExtensionName, extensionPropertyName, ref propertyValue))
                            {
                                propertyValue = this.m_SpatializerEditor.GetExtensionPropertyDefaultValue(j);
                                audioListener.WriteExtensionProperty(AudioExtensionManager.GetSpatializerName(), listenerSpatializerExtensionName, extensionPropertyName, propertyValue);
                            }
                        }
                    }
                }
            }
            this.m_AddSpatializerExtensionMixedValues = false;
        }
        // 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;
        }
Ejemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            base.serializedObject.Update();
            bool flag = (this.m_AddSpatializerExtension && !this.m_AddSpatializerExtensionMixedValues) || !base.serializedObject.isEditingMultipleObjects;

            if (AudioExtensionManager.IsListenerSpatializerExtensionRegistered() && flag)
            {
                EditorGUI.showMixedValue = this.m_AddSpatializerExtensionMixedValues;
                bool flag2 = EditorGUILayout.Toggle(this.addSpatializerExtensionLabel, this.m_AddSpatializerExtension, new GUILayoutOption[0]);
                EditorGUI.showMixedValue = false;
                bool flag3 = false;
                if (this.m_AddSpatializerExtension != flag2)
                {
                    this.m_AddSpatializerExtension = flag2;
                    if (this.m_AddSpatializerExtension)
                    {
                        this.CreateExtensionEditors();
                        if (this.m_SpatializerEditor != null)
                        {
                            flag3 = this.m_SpatializerEditor.FindAudioExtensionProperties(base.serializedObject);
                        }
                    }
                    else
                    {
                        this.ClearExtensionProperties();
                        this.DestroyExtensionEditors();
                        flag3 = false;
                    }
                }
                else if (this.m_SpatializerEditor != null)
                {
                    flag3 = this.m_SpatializerEditor.FindAudioExtensionProperties(base.serializedObject);
                    if (!flag3)
                    {
                        this.m_AddSpatializerExtension = false;
                        this.ClearExtensionProperties();
                        this.DestroyExtensionEditors();
                    }
                }
                if (this.m_SpatializerEditor != null && flag3)
                {
                    EditorGUI.indentLevel++;
                    this.m_SpatializerEditor.OnAudioListenerGUI();
                    EditorGUI.indentLevel--;
                    for (int i = 0; i < base.targets.Length; i++)
                    {
                        AudioListener audioListener = base.targets[i] as AudioListener;
                        if (audioListener != null)
                        {
                            AudioListenerExtension spatializerExtension = AudioExtensionManager.GetSpatializerExtension(audioListener);
                            if (spatializerExtension != null)
                            {
                                string name = AudioExtensionManager.GetListenerSpatializerExtensionType().Name;
                                for (int j = 0; j < this.m_SpatializerEditor.GetNumExtensionProperties(); j++)
                                {
                                    PropertyName extensionPropertyName = this.m_SpatializerEditor.GetExtensionPropertyName(j);
                                    float        propertyValue         = 0f;
                                    if (audioListener.ReadExtensionProperty(name, extensionPropertyName, ref propertyValue))
                                    {
                                        spatializerExtension.WriteExtensionProperty(extensionPropertyName, propertyValue);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            base.serializedObject.ApplyModifiedProperties();
        }
        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();
        }