punchey
New Member
Posts: 7
Posts: 7
|
Post by punchey on Feb 8, 2016 1:12:49 GMT
What is the proper procedure for removing a sound group added to the scene at runtime by instantiation of a Dynamic Sound Group Creator prefab? There doesn't seem to be any convenient way to get ahold of the transform of such a sound group. Is there any alternative way to unload/remove soundgroups created at runtime? I'm wanting to swap it out with something else with the same name in the same scene.
|
|
|
Post by DarkTonic Dev on Feb 8, 2016 16:27:08 GMT
Indeed there is a method. It should be on the API website, if you've taken a look there?
MasterAudio.RemoveSoundGroup(soundGroupName);
|
|
punchey
New Member
Posts: 7
Posts: 7
|
Post by punchey on Feb 8, 2016 19:50:26 GMT
|
|
|
Post by DarkTonic Dev on Feb 8, 2016 20:36:23 GMT
You're right of course. I missed that detail. Fixed for the next version. You can change this if you need it now.
Change RemoveSoundGroup method to the following in MasterAudio.cs
/// <summary> /// This method will delete a Sound Group, and all variations from the current Scene's Master Audio object. /// </summary> /// <param name="sType">The name of the Sound Group.</param> public static void RemoveSoundGroup(string sType) { if (SafeInstance == null) { return; }
var grp = GrabGroup(sType); if (grp == null) { return; }
var groupTrans = grp.transform;
var ma = Instance;
if (ma.duckingBySoundType.ContainsKey(sType)) { ma.duckingBySoundType.Remove(sType); }
_randomizer.Remove(sType); _randomizerLeftovers.Remove(sType); _clipsPlayedBySoundTypeOldestFirst.Remove(sType); AudioSourcesBySoundType.Remove(sType); LastTimeSoundGroupPlayed.Remove(sType);
// ReSharper disable TooWideLocalVariableScope AudioSource aSource; SoundGroupVariation aVar; Transform aChild; // ReSharper restore TooWideLocalVariableScope
// delete resource file pointers to Audio Sources being deleted for (var i = 0; i < groupTrans.childCount; i++) { aChild = groupTrans.GetChild(i); aSource = aChild.GetComponent<AudioSource>(); aVar = aChild.GetComponent<SoundGroupVariation>();
switch (aVar.audLocation) { case AudioLocation.ResourceFile: AudioResourceOptimizer.DeleteAudioSourceFromList(aVar.resourceFileName, aSource); break; case AudioLocation.FileOnInternet: AudioResourceOptimizer.DeleteAudioSourceFromList(aVar.internetFileUrl, aSource); break; }
}
groupTrans.parent = null; // ReSharper disable once ArrangeStaticMemberQualifier GameObject.Destroy(groupTrans.gameObject); }
Then change the line that calls is in DynamicSoundGroupCreator.cs to this:
MasterAudio.RemoveSoundGroup(_groupsToRemove[i].name);
|
|
punchey
New Member
Posts: 7
Posts: 7
|
Post by punchey on Feb 8, 2016 22:01:46 GMT
Thanks so much!
|
|
|
Post by DarkTonic Dev on Feb 8, 2016 22:07:02 GMT
No problem.
|
|