AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
AudioSourcesReference.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System.Collections.Generic;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity
8 {
14  public class AudioSourcesReference : MonoBehaviour
15  {
16  private List<AudioSource> audioSources;
17  public List<AudioSource> AudioSources
18  {
19  get
20  {
21  return audioSources;
22  }
23  }
24 
25  public AudioSource AddNewAudioSource()
26  {
27  var source = this.gameObject.AddComponent<AudioSource>();
28  source.playOnAwake = false;
29  source.dopplerLevel = 0f;
30  source.enabled = false;
31  audioSources.Add(source);
32  return source;
33  }
34 
35  private void Awake()
36  {
37  audioSources = new List<AudioSource>();
38  foreach (AudioSource audioSource in GetComponents<AudioSource>())
39  {
40  audioSources.Add(audioSource);
41  }
42  }
43 
44  private void OnDestroy()
45  {
46  // AudioSourcesReference created all these components and nothing else should use them.
47  foreach (AudioSource audioSource in audioSources)
48  {
49  Object.Destroy(audioSource);
50  }
51 
52  audioSources = null;
53  }
54  }
55 }
The AudioSourcesReference class encapsulates a cache of references to audio source components on a gi...