Skip to content

Instantly share code, notes, and snippets.

@martindevans
Created October 19, 2023 15:14
Show Gist options
  • Save martindevans/6fbeb64df5d4e52d04af13a99fb3237e to your computer and use it in GitHub Desktop.
Save martindevans/6fbeb64df5d4e52d04af13a99fb3237e to your computer and use it in GitHub Desktop.
private IEnumerator CoResumePlayback()
{
var net = _net as MonoBehaviour;
if (net != null)
{
// Disable Dissonance networking, wait a short while, then re-enable it. This will reset everything
// in Dissonance as if it has connected to a new session.
net.enabled = false;
for (var i = 0; i < 30; i++)
yield return null;
net.enabled = true;
}
else
{
// Force a capture pipeline reset to resume recording
_capture.ForceReset();
// Many network systems are quite confused by application pauses. Some of them delivering a large number of packets all at once
// when the pause ends. Wait for a few frames to give the network system some time to sort itself out.
for (var i = 0; i < 30; i++)
yield return null;
// Flush playback pipelines for all remote speakers, discarding all buffered voice sessions
var players = Players;
for (var i = 0; i < players.Count; i++)
{
var player = players[i];
if (player.IsLocalPlayer)
continue;
player.PlaybackInternal?.ForceReset();
}
}
// Allow remote voices to start playing
MuteAllRemoteVoices = false;
// Now that this coroutine is done clear the state
_resumeCo = null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment