Skip to content

Commit 370089f

Browse files
author
Stephen Hodgson
authored
Merge pull request #500 from HodgsonSDAS/HTK-audio
UAudioManager added null check in PlayEvent
2 parents 404ba99 + 9eef801 commit 370089f

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

Assets/HoloToolkit/SpatialSound/Scripts/UAudioManager/UAudioManager.cs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,7 @@ public void PlayEvent(string eventName)
7373
/// <param name="messageOnAudioEnd">The Message to Send to the GameObject when the sound has finished playing.</param>
7474
public void PlayEvent(string eventName, GameObject emitter, string messageOnAudioEnd = null)
7575
{
76-
PlayEvent(
77-
eventName,
78-
emitter,
79-
null,
80-
null,
81-
messageOnAudioEnd);
82-
}
83-
84-
/// <summary>
85-
/// Plays an AudioEvent.
86-
/// </summary>
87-
/// <param name="eventName">The name associated with the AudioEvent.</param>
88-
/// <param name="primarySource">The AudioSource component to use as the primary source for the event.</param>
89-
public void PlayEvent(string eventName, AudioSource primarySource)
90-
{
91-
PlayEvent(eventName, primarySource, null);
76+
PlayEvent(eventName, emitter, null, null, messageOnAudioEnd);
9277
}
9378

9479
/// <summary>
@@ -97,14 +82,9 @@ public void PlayEvent(string eventName, AudioSource primarySource)
9782
/// <param name="eventName">The name associated with the AudioEvent.</param>
9883
/// <param name="primarySource">The AudioSource component to use as the primary source for the event.</param>
9984
/// <param name="secondarySource">The AudioSource component to use as the secondary source for the event.</param>
100-
public void PlayEvent(string eventName,
101-
AudioSource primarySource,
102-
AudioSource secondarySource)
85+
public void PlayEvent(string eventName, AudioSource primarySource, AudioSource secondarySource = null)
10386
{
104-
PlayEvent(eventName,
105-
primarySource.gameObject,
106-
primarySource,
107-
secondarySource);
87+
PlayEvent(eventName, primarySource.gameObject, primarySource, secondarySource);
10888
}
10989

11090
/// <summary>
@@ -115,11 +95,7 @@ public void PlayEvent(string eventName,
11595
/// <param name="primarySource">The AudioSource component to use as the primary source for the event.</param>
11696
/// <param name="secondarySource">The AudioSource component to use as the secondary source for the event.</param>
11797
/// <param name="messageOnAudioEnd">The Message to Send to the GameObject when the sound has finished playing.</param>
118-
private void PlayEvent(string eventName,
119-
GameObject emitter,
120-
AudioSource primarySource,
121-
AudioSource secondarySource,
122-
string messageOnAudioEnd = null)
98+
private void PlayEvent(string eventName, GameObject emitter, AudioSource primarySource, AudioSource secondarySource, string messageOnAudioEnd = null)
12399
{
124100
if (!CanPlayNewEvent())
125101
{
@@ -132,11 +108,17 @@ private void PlayEvent(string eventName,
132108
emitter = gameObject;
133109
}
134110

111+
if (string.IsNullOrEmpty(eventName))
112+
{
113+
Debug.LogWarning("Audio Event string is null or empty!");
114+
return;
115+
}
116+
135117
AudioEvent currentEvent;
136118

137119
if (!eventsDictionary.TryGetValue(eventName, out currentEvent))
138120
{
139-
Debug.LogFormat( "Could not find event \"{0}\"", eventName);
121+
Debug.LogFormat("Could not find event \"{0}\"", eventName);
140122
return;
141123
}
142124

0 commit comments

Comments
 (0)