Manage presentations
You can use the presentation service to let participants start and stop presentations, and join and leave presentations.
Prerequisites
Before you manage your presentations, you must first manage your room.
Instantiate the presentation service
To instantiate the presentation service, see the following steps:
- Go to your
PlatformServicesscript in yourAssets/Scriptsdirectory. In your
PlatformServicesscript file, update thePlatformServicesclass with a public reference toIPresentationServiceand a private reference toPresentationService.static PresentationService s_PresentationService; public static IPresentationService PresentationService => s_PresentationService;Initialize the services in the
InitializeAsyncmethod. The variables provided in the constructor are defined in get started and in the Identity authentication guide.public static async Task InitializeAsync() { // ... s_PresentationService = new PresentationService(s_ServiceHttpClient, s_PresenceManager, s_ServiceHostResolver); // ... }Shut down the services in the
Shutdownmethod.public static void Shutdown() { // ... s_PresenceManager = null; // ... }
Start and stop presentations
You can use presentation mode to start and stop a presentation attached to a room. Participants who join a presentation are notified of any updates.
To manage a presentation, see the following steps:
- In your scene, create Join Presentation, Leave Presentation, Start Presentation and Stop Presentation buttons.

- Go to GameObject > Create Empty and name the new game object PresentationManager.
- In your
Assets/Scriptsdirectory, create a new script and name itPresentationManager. - Attach the
PresentationManagerscript to your PresentationManager game object. In your
PresentationManagerscript file, use thePresentationManagerclass to do the following:- Reference an
IPresentationServiceand anISessionProvider - Reference the join, leave, start and stop presentation buttons
- Store the current session
Describe whether the participant has joined or started a presentation
public class PresentationManager : MonoBehaviour { IPresentationService m_PresentationService; ISessionProvider m_SessionProvider; [SerializeField] Button m_JoinButton; [SerializeField] Button m_LeaveButton; [SerializeField] Button m_StartButton; [SerializeField] Button m_StopButton; ISession m_CurrentSession; bool m_HasJoined; bool m_HasStarted; }
- Reference an
Use the
Awakemethod to retrieve services from PlatformServices and to subscribe to theSessionChangedevent. Use theOnDestroymethod to unsubscribe from the event.void Awake() { m_PresentationService = PlatformServices.PresentationService; m_SessionProvider = PlatformServices.SessionProvider; m_SessionProvider.SessionChanged += OnSessionChanged; m_JoinButton.onClick.AddListener(new UnityEngine.Events.UnityAction(OnJoinClickAsync)); m_LeaveButton.onClick.AddListener(new UnityEngine.Events.UnityAction(OnLeaveClick)); m_StartButton.onClick.AddListener(new UnityEngine.Events.UnityAction(OnStartClick)); m_StopButton.onClick.AddListener(new UnityEngine.Events.UnityAction(OnStopClick)); } void OnDestroy() { m_JoinButton.onClick.RemoveAllListeners(); m_LeaveButton.onClick.RemoveAllListeners(); m_StartButton.onClick.RemoveAllListeners(); m_StopButton.onClick.RemoveAllListeners(); m_SessionProvider.SessionChanged -= OnSessionChanged; }Use the
OnSessionChangedmethod to clean up any previous sessions and to make sure the buttons are displayed correctly.async void OnSessionChanged(ISession session) { m_JoinButton.interactable = false; m_LeaveButton.interactable = false; m_StartButton.interactable = false; m_StopButton.interactable = false; // Cleans up any previous sessions if (m_CurrentSession != null) { if (m_HasJoined) await m_PresentationService.LeavePresentationAsync(); if (m_HasStarted) await m_PresentationService.StopPresentationAsync(); } m_HasJoined = false; m_HasStarted = false; m_CurrentSession = session; if (session != null) { m_JoinButton.interactable = true; m_StartButton.interactable = true; } }Use the
OnJoinClickAsyncmethod to implement callbacks for the button clicks.async void OnJoinClickAsync() { m_JoinButton.interactable = false; m_StartButton.interactable = false; await m_PresentationService.JoinPresentationAsync(); m_HasJoined = true; m_LeaveButton.interactable = true; } async void OnLeaveClick() { m_LeaveButton.interactable = false; await m_PresentationService.LeavePresentationAsync(); m_HasJoined = false; m_JoinButton.interactable = true; m_StartButton.interactable = true; } async void OnStartClick() { m_StartButton.interactable = false; m_JoinButton.interactable = false; await m_PresentationService.StartPresentationAsync(); m_HasStarted = true; m_StopButton.interactable = true; } async void OnStopClick() { m_StopButton.interactable = false; await m_PresentationService.StopPresentationAsync(); m_HasStarted = false; m_StartButton.interactable = true; m_JoinButton.interactable = true; }
(Optional) Display information about a presentation
To display information about a presentation, see the following steps:
- In your scene, create a text field to display information about the presentation mode.
- In your
Assets/Scriptsdirectory, create a new script and name itPresentationTextUpdater. - Attach the
PresentationTextUpdaterscript to your PresentationManager game object. In your
PresentationTextUpdaterscript file, use thePresentationTextUpdaterclass to reference anIPresentationServiceand your text field.public class PresentationTextUpdater : MonoBehaviour { IPresentationService m_PresentationService; [SerializeField] Text m_TextField; }Use the
Awakemethod to retrieve services from PlatformServices and to subscribe to thePresentationEventevent. Use theOnDestroymethod to unsubscribe from the event.void Awake() { m_PresentationService = PlatformServices.PresentationService; m_PresentationService.PresentationEvent += OnPresentationEvent; } void OnDestroy() { m_PresentationService.PresentationEvent -= OnPresentationEvent; }Use the
OnPresentationEventmethod to update the text with information about the presentation.void OnPresentationEvent(PresentationEventDetails details) { var sb = new StringBuilder(); sb.AppendLine("Presenter:"); sb.AppendLine(details.PresenterParticipantId.ToString()); sb.AppendLine("Attendees:"); foreach (var attendee in details.AttendeeParticipantIds) { sb.AppendLine(attendee.ToString()); } m_TextField.text = sb.ToString(); }