Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

AudioSettings.Reset

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public static function Reset(config: AudioConfiguration): bool;
public static bool Reset(AudioConfiguration config);

Parámetros

config The new configuration to be used.

Valor de retorno

bool True if all settings could be successfully applied.

Descripción

Performs a change of the device configuration. In response to this the AudioSettings.OnAudioConfigurationChanged delegate is invoked with the argument deviceWasChanged=false. It cannot be guaranteed that the exact settings specified can be used, but the an attempt is made to use the closest match supported by the system.


        
using UnityEngine;
using System.Collections;

public class TestAudioConfiguration : MonoBehaviour { void Start () { AudioSettings.OnAudioConfigurationChanged += OnAudioConfigurationChanged; }

void OnAudioConfigurationChanged(bool deviceWasChanged) { Debug.Log(deviceWasChanged ? "Device was changed" : "Reset was called"); if (deviceWasChanged) { AudioConfiguration config = AudioSettings.GetConfiguration (); config.dspBufferSize = 64; AudioSettings.Reset (config); } GetComponent<AudioSource>().Play (); }

static int[] validSpeakerModes = { (int)AudioSpeakerMode.Mono, (int)AudioSpeakerMode.Stereo, (int)AudioSpeakerMode.Quad, (int)AudioSpeakerMode.Surround, (int)AudioSpeakerMode.Mode5point1, (int)AudioSpeakerMode.Mode7point1 };

static int[] validDSPBufferSizes = { 32, 64, 128, 256, 340, 480, 512, 1024, 2048, 4096, 8192 };

static int[] validSampleRates = { 11025, 22050, 44100, 48000, 88200, 96000, };

static int[] validNumRealVoices = { 1, 2, 4, 8, 16, 32, 50, 64, 100, 128, 256, 512, };

static int[] validNumVirtualVoices = { 1, 2, 4, 8, 16, 32, 50, 64, 100, 128, 256, 512, };

int GUIRow(string name, int[] valid, int value, ref bool modified) { GUILayout.BeginHorizontal (); GUILayout.Button (name + "=" + value); for (int i = 0; i < valid.Length; i++) { string s = valid [i].ToString (); if (valid [i] == value) s = "[" + s + "]"; if (GUILayout.Button (s)) { value = valid [i]; modified = true; } } GUILayout.EndHorizontal (); return value; }

void OnGUI() { AudioSource source = GetComponent<AudioSource> (); bool modified = false;

AudioConfiguration config = AudioSettings.GetConfiguration ();

config.speakerMode = (AudioSpeakerMode)GUIRow ("speakerMode", validSpeakerModes, (int)config.speakerMode, ref modified); config.dspBufferSize = GUIRow ("dspBufferSize", validDSPBufferSizes, config.dspBufferSize, ref modified); config.sampleRate = GUIRow ("sampleRate", validSampleRates, config.sampleRate, ref modified); config.numRealVoices = GUIRow ("RealVoices", validNumRealVoices, config.numRealVoices, ref modified); config.numVirtualVoices = GUIRow ("numVirtualVoices", validNumVirtualVoices, config.numVirtualVoices, ref modified);

if (modified) AudioSettings.Reset (config);

if (GUILayout.Button ("Start")) source.Play ();

if (GUILayout.Button ("Stop")) source.Stop (); } }