private AudioMixerGroupController DuplicateGroupRecurse(AudioMixerGroupController sourceGroup, bool recordUndo)
{
var targetGroup = new AudioMixerGroupController(this);
// Copy effects
var targetEffectsList = new List <AudioMixerEffectController>();
foreach (var sourceEffect in sourceGroup.effects)
{
targetEffectsList.Add(CopyEffect(sourceEffect));
}
// Copy child groups
var targetChildren = new List <AudioMixerGroupController>();
foreach (var childGroup in sourceGroup.children)
{
targetChildren.Add(DuplicateGroupRecurse(childGroup, recordUndo));
}
targetGroup.name = sourceGroup.name + " - Copy";
targetGroup.PreallocateGUIDs();
targetGroup.effects = targetEffectsList.ToArray();
targetGroup.children = targetChildren.ToArray();
targetGroup.solo = sourceGroup.solo;
targetGroup.mute = sourceGroup.mute;
targetGroup.bypassEffects = sourceGroup.bypassEffects;
float value;
foreach (var s in snapshots)
{
if (s.GetValue(sourceGroup.GetGUIDForVolume(), out value))
{
s.SetValue(targetGroup.GetGUIDForVolume(), value);
}
if (s.GetValue(sourceGroup.GetGUIDForPitch(), out value))
{
s.SetValue(targetGroup.GetGUIDForPitch(), value);
}
if (s.GetValue(sourceGroup.GetGUIDForSend(), out value))
{
s.SetValue(targetGroup.GetGUIDForSend(), value);
}
}
AssetDatabase.AddObjectToAsset(targetGroup, this);
if (recordUndo)
{
Undo.RegisterCreatedObjectUndo(targetGroup, targetGroup.name);
}
// Add to view if source is shown (so it's visible in the channelstrip)
if (CurrentViewContainsGroup(sourceGroup.groupID))
{
targetGroup.controller.AddGroupToCurrentView(targetGroup);
}
return(targetGroup);
}