Skip to content

Instantly share code, notes, and snippets.

@Arakade
Created January 24, 2014 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arakade/8608912 to your computer and use it in GitHub Desktop.
Save Arakade/8608912 to your computer and use it in GitHub Desktop.
Patch for Unity3D MasterAudio v3.3.6 producing all sound variations when PlaySound*AndForget() methods used (more makePlaySoundResult use needed). Diff looks much larger than it actually is due to added indentation needed.
diff --git "a/C:\\Users\\User\\AppData\\Local\\Temp\\TortoiseGit\\MasEC0A.tmp\\MasterAudio-b3070d8-left.cs" "b/C:\\Users\\User\\Dev\\Unity3D\\MusicExperiments\\Assets\\DarkTonic\\MasterAudio\\Scripts\\Singleton\\MasterAudio.cs"
index 4d6ccf1..c9b20e9 100644
--- "a/C:\\Users\\User\\AppData\\Local\\Temp\\TortoiseGit\\MasEC0A.tmp\\MasterAudio-b3070d8-left.cs"
+++ "b/C:\\Users\\User\\Dev\\Unity3D\\MusicExperiments\\Assets\\DarkTonic\\MasterAudio\\Scripts\\Singleton\\MasterAudio.cs"
@@ -1092,62 +1092,67 @@ public class MasterAudio : MonoBehaviour {
do {
playedState = PlaySoundIfAvailable(randomSource, sourcePosition, volumePercentage, pitch, _group, sourceTrans, attachToSource, delaySoundTime, useVector3, makePlaySoundResult);
-
- if (playedState != null && (playedState.SoundPlayed || playedState.SoundScheduled)) {
- playedSound = true;
-
- if (isNonSpecific && randomIndex.HasValue) { // only if successfully played!
- choices.RemoveAt(randomIndex.Value);
-
- if (choices.Count == 0) {
- LogIfLoggingEnabled("Reloading sound: " + sType, sType);
+
+ if (makePlaySoundResult) {
+ if (playedState != null && (playedState.SoundPlayed || playedState.SoundScheduled)) {
+ playedSound = true;
+
+ if (isNonSpecific && randomIndex.HasValue) { // only if successfully played!
+ choices.RemoveAt(randomIndex.Value);
- RefillSoundGroupPool(sType);
- }
- }
+ if (choices.Count == 0) {
+ LogIfLoggingEnabled("Reloading sound: " + sType, sType);
+
+ RefillSoundGroupPool(sType);
+ }
+ }
- if (_group._group.curVariationSequence == MasterAudioGroup.VariationSequence.TopToBottom && _group._group.useInactivePeriodPoolRefill) {
- UpdateRefillTime(sType, _group._group.inactivePeriodSeconds);
- }
- } else if (isNonSpecific) {
- // try the other ones
- if (otherChoices.Count > 0) {
- randomSource = sources[otherChoices[0]];
- LogIfLoggingEnabled("Child was busy. Cueing child {" + sources[otherChoices[0]].source.name + "} of " + sType, sType);
- otherChoices.RemoveAt(0);
+ if (_group._group.curVariationSequence == MasterAudioGroup.VariationSequence.TopToBottom && _group._group.useInactivePeriodPoolRefill) {
+ UpdateRefillTime(sType, _group._group.inactivePeriodSeconds);
+ }
+ } else if (isNonSpecific) {
+ // try the other ones
+ if (otherChoices.Count > 0) {
+ randomSource = sources[otherChoices[0]];
+ LogIfLoggingEnabled("Child was busy. Cueing child {" + sources[otherChoices[0]].source.name + "} of " + sType, sType);
+ otherChoices.RemoveAt(0);
+ }
}
+ } else {
+ playedSound = true; // assume success (TODO: Indent above)
}
}
while (!playedSound && otherChoices.Count > 0); // repeat until you've either played the sound or exhausted all possibilities.
-
- if (playedState != null) {
- if (playedState.SoundPlayed) {
- // sound play worked! Duck music if a ducking sound.
- var matchingDuck = ma.musicDuckingSounds.Find(delegate(DuckGroupInfo obj) {
- return obj.soundType == sType;
- });
-
- if (ma.EnableMusicDucking && matchingDuck != null) {
- // duck music
- var duckLength = randomSource.source.audio.clip.length;
- var duckPitch = randomSource.source.pitch;
+ if (makePlaySoundResult) {
+ if (playedState != null) {
+ if (playedState.SoundPlayed) {
+ // sound play worked! Duck music if a ducking sound.
+ var matchingDuck = ma.musicDuckingSounds.Find(delegate(DuckGroupInfo obj) {
+ return obj.soundType == sType;
+ });
- var pcs = PlaylistController.Instances;
- for (var i = 0; i < pcs.Count; i++) {
- pcs[i].DuckMusicForTime(duckLength, duckPitch, matchingDuck.riseVolStart);
+ if (ma.EnableMusicDucking && matchingDuck != null) {
+ // duck music
+ var duckLength = randomSource.source.audio.clip.length;
+ var duckPitch = randomSource.source.pitch;
+
+ var pcs = PlaylistController.Instances;
+ for (var i = 0; i < pcs.Count; i++) {
+ pcs[i].DuckMusicForTime(duckLength, duckPitch, matchingDuck.riseVolStart);
+ }
+
+ if (pcs.Count == 0) {
+ Debug.LogWarning("Playlist Controller is not in the Scene. Cannot duck music.");
+ }
}
- if (pcs.Count == 0) {
- Debug.LogWarning("Playlist Controller is not in the Scene. Cannot duck music.");
- }
+ return playedState;
+ }
+ } else {
+ if (otherChoices.Count == 0) {
+ LogIfLoggingEnabled("All children of " + sType + " were busy. Will not play this sound for this instance.", sType);
}
-
- return playedState;
- }
- } else {
- if (playedState == null && otherChoices.Count == 0) {
- LogIfLoggingEnabled("All children of " + sType + " were busy. Will not play this sound for this instance.", sType);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment