Background Character Sample
This scene shows how you can start a session without binding it to an animator/audio source pair in order to have a background session ready to go at any time. This idea can be applied to any situation where a player may interact with a Rapport character which will need to be ready to listen as quickly as possible.
BackgroundCharacterSample.cs
This script connects the UI and character in this sample scene with Rapport. Although this one looks very similar to Rapport Basic Sample Scene, there are some small differences. The scene contains 2 game objects with the names “FirstRapportViewer” and “SecondRapportViewer” which will be swapped between when the “Swap Session” button is clicked.
How the BackgroundCharacterSample Class Works
Note about multiple session references: The
Sessionfield and therapportMicrophonefield will always be the one that is connected to the character, and I will refer to these as the “foreground” session and Rapport microphone.StartRapportSession(): In addition to starting the foregroundSessionlike the basic sample it also starts theBackgroundSessionusing thebackgroundMicrophone.WaitForSessionStart(): Only the foreground session is bound to the audio source and animator on the character. The background session is left unbound for now; this will initialize all the data streams and connect to Rapport web as another completely separate session, but will not display the animation or audio in any way. Please note that this data will continue to be streamed in and discarded until the player is bound.SwapSession()/DoSwapSession(): When the user presses the “Swap Session” button on the UI, it will start a coroutine. This coroutine:Swaps the foreground and background sessions and microphones
Stops the old foreground session, causing it to be unbound from the audio source and animator
Restarts the old session using the microphone that matches up with it
Binds the new foreground session to the audio source and animator to enable Rapport to control it