AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
AudioEvent.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;
5 using UnityEngine;
6 using UnityEngine.Audio;
7 
8 namespace HoloToolkit.Unity
9 {
13  public enum AudioContainerType
14  {
15  Random,
16  Sequence,
20  }
21 
26  {
27  KillOldest,
29  }
30 
35  {
39  TwoD,
43  ThreeD,
48  }
49 
53  [Serializable]
54  public class AudioEvent : IComparable, IComparable<AudioEvent>
55  {
56  [Tooltip("The name of this AudioEvent.")]
57  public string Name = "_NewAudioEvent";
58 
59  [Tooltip("How this sound is to be positioned.")]
60  public SpatialPositioningType Spatialization = SpatialPositioningType.TwoD;
61 
62  [Tooltip("The size of the Microsoft Spatial Sound room. Only used when positioning is set to SpatialSound.")]
64 
65  [Tooltip("The volume attenuation curve for simple 3D sounds. Used when positioning is set to 3D or Spatial")]
66  public AnimationCurve AttenuationCurve = AnimationCurve.EaseInOut(0f, 1f, 1f, 0f); // By default simple attenuation
67 
68  [Tooltip("The spatial attenuation curve for simple 3D sounds. Only used when positioning is set to 3D")]
69  public AnimationCurve SpatialCurve = AnimationCurve.EaseInOut(0f, 1f, 1f, 1f); // by default Full 3D sound
70 
71  [Tooltip("The spread attenuation curve for simple 3D sounds. Only used when positioning is set to 3D")]
72  public AnimationCurve SpreadCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 0f); // by default no spread
73 
74  [Tooltip("The reverb attenuation curve for simple 3D sounds. Only used when positioning is set to 3D")]
75  public AnimationCurve ReverbCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 0f); // by default no reverb
76 
77  [Tooltip("The maximum attenuation distance for simple 3D sounds. Only used when positioning is set to 3D")]
78  [Range(1f, 500f)]
79  public float MaxDistanceAttenuation3D = 100f;
80 
81  [Tooltip("The AudioMixerGroup to use when playing.")]
82  public AudioMixerGroup AudioBus;
83 
84  [Tooltip("The default or center pitch around which randomization can be done.")]
85  [Range(-3.0f, 3.0f)]
86  public float PitchCenter = 1.0f;
87 
92  [HideInInspector]
93  public float PitchRandomization;
94 
95  [Tooltip("The default or center volume level around which randomization can be done.")]
96  [Range(0.0f, 1.0f)]
97  public float VolumeCenter = 1.0f;
98 
103  [HideInInspector]
104  public float VolumeRandomization;
105 
106  [Tooltip("The default or center panning. Only used when positioning is set to 2D.")]
107  [Range(-1.0f, 1.0f)]
108  public float PanCenter;
109 
114  [HideInInspector]
115  public float PanRandomization;
116 
117 
118  [Tooltip("Time, in seconds, for the audio to fade from 0 to the selected volume. Does not apply to continuous containers in which the Crossfade time property is used.")]
119  [Range(0f, 20f)]
120  public float FadeInTime;
121 
122  [Tooltip("Time, in seconds, for the audio to fade out from the selected volume to 0. Does not apply to continuous containers in which the Crossfade time property is used.")]
123  [Range(0f, 20f)]
124  public float FadeOutTime;
125 
126  [Tooltip("The maximum number of instances that should be allowed at a time for this event. Any new instances will be suppressed.")]
127  public int InstanceLimit;
128 
129  [Tooltip("The amount of time in seconds that an event will remain active past when the sound ends. Useful for limiting the instances of an event beyond the clip play time.")]
130  public float InstanceTimeBuffer;
131 
132  [Tooltip("The behavior when the instance limit is reached.")]
133  public AudioEventInstanceBehavior AudioEventInstanceBehavior = AudioEventInstanceBehavior.KillOldest;
134 
138  public AudioContainer Container = new AudioContainer();
139 
144  public bool IsContinuous()
145  {
146  return Container.ContainerType == AudioContainerType.ContinuousRandom ||
147  Container.ContainerType == AudioContainerType.ContinuousSequence;
148  }
149 
157  public int CompareTo(object obj)
158  {
159  if (obj == null) { return 1; }
160 
161  var tempEvent = obj as AudioEvent;
162 
163  if (tempEvent != null)
164  {
165  return CompareTo(tempEvent);
166  }
167 
168  throw new ArgumentException("Object is not an AudioEvent");
169  }
170 
177  public int CompareTo(AudioEvent other)
178  {
179  return other == null ? 1 : string.CompareOrdinal(Name, other.Name);
180  }
181  }
182 }
bool IsContinuous()
Is this AudioEvent&#39;s container a continuous container?
Definition: AudioEvent.cs:144
int CompareTo(AudioEvent other)
Compares this AudioEvent with another AudioEvent.
Definition: AudioEvent.cs:177
The SpatialSoundSettings class provides a set of methods that simplify making modifications to Micros...
AudioContainerType
The different rules for how audio should be played back.
Definition: AudioEvent.cs:13
int CompareTo(object obj)
Compares this AudioEvent with another object.
Definition: AudioEvent.cs:157
SpatialPositioningType
The different types of spatial positioning.
Definition: AudioEvent.cs:34
The AudioEvent class is the main component of UAudioManager and contains settings and a container for...
Definition: AudioEvent.cs:54
float PanRandomization
The amount in either direction from Pan Center that panning can randomly vary upon playing the event...
Definition: AudioEvent.cs:115
The AudioContainer class is sound container for an AudioEvent. It also specifies the rules of how to ...
float VolumeRandomization
The amount in either direction from Volume Center that the volume can randomly vary upon playing the ...
Definition: AudioEvent.cs:104
AudioEventInstanceBehavior
Defines the behavior for when the instance limit is reached for a particular event.
Definition: AudioEvent.cs:25
const SpatialSoundRoomSizes DefaultSpatialSoundRoom
AudioMixerGroup AudioBus
Definition: AudioEvent.cs:82
AudioContainerType ContainerType
SpatialSoundRoomSizes
Room sizes for the Microsoft Spatial Sound Spatializer.
float PitchRandomization
The amount in either direction from Pitch Center that the pitch can randomly vary upon playing the ev...
Definition: AudioEvent.cs:93