Search Unity

What is the Scene View's Audio Play Toggle For?

Discussion in 'Audio & Video' started by SonicBloomEric, Apr 5, 2016.

  1. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    1,085
    There is a little audio icon in the Scene View's icon bar (above the scene content). The text says "Toggles audio on or off." When enabled it will cause any AudioSource with Play On Awake set and an Audio Clip loaded to begin playing back. The "Mute audio" button in the Game View will actually mute this audio (disabling/enabling a playing AudioSource will also stop the audio it's playing until you next refocus the Scene View. Here is the decompiled code that does it (located in UnityEditor.SceneView via the MonoDevelop Assembly Browser):

    Code (CSharp):
    1.     private void RefreshAudioPlay ()
    2.         {
    3.             if (SceneView.s_AudioSceneView != null && SceneView.s_AudioSceneView != this && SceneView.s_AudioSceneView.m_AudioPlay) {
    4.                 SceneView.s_AudioSceneView.m_AudioPlay = false;
    5.                 SceneView.s_AudioSceneView.Repaint ();
    6.             }
    7.             AudioSource[] array = (AudioSource[])Object.FindObjectsOfType (typeof(AudioSource));
    8.             AudioSource[] array2 = array;
    9.             for (int i = 0; i < array2.Length; i++) {
    10.                 AudioSource audioSource = array2 [i];
    11.                 if (audioSource.playOnAwake) {
    12.                     if (!this.m_AudioPlay) {
    13.                         audioSource.Stop ();
    14.                     }
    15.                     else {
    16.                         if (!audioSource.isPlaying) {
    17.                             audioSource.Play ();
    18.                         }
    19.                     }
    20.                 }
    21.             }
    22.             AudioUtil.SetListenerTransform ((!this.m_AudioPlay) ? null : this.m_Camera.transform);
    23.             SceneView.s_AudioSceneView = this;
    24.         }

    Does anyone have any idea what you would actually use this feature for?
     
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    No but interested :)
     
    SonicBloomEric likes this.
  3. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    AFAIK that's for when you're setting up ambient audio sources and such in a level, you can hit that button to preview what it sounds like without having to hit play.
     
  4. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    1,085
    I guess that makes sense. Feels very odd, given that it would turn on everything in the scene. Perhaps a better name for this would be helpful. Something like "Enable Ambient (Play On Awake) Audio Playback".
     
  5. maristammik

    maristammik

    Joined:
    Jun 19, 2016
    Posts:
    1
    SonicBloomEric likes this.