docs.unity3d.com
    Show / Hide Table of Contents

    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:

    1. Go to your PlatformServices script in your Assets/Scripts directory.
    2. In your PlatformServices script file, update the PlatformServices class with a public reference to IPresentationService and a private reference to PresentationService.

       static PresentationService s_PresentationService;
      
       public static IPresentationService PresentationService => s_PresentationService;
      
    3. Initialize the services in the InitializeAsync method. 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);
      
           // ...
       }
      
    4. Shut down the services in the Shutdown method.

       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:

    1. In your scene, create Join Presentation, Leave Presentation, Start Presentation and Stop Presentation buttons.
      Screenshot of presentation mode buttons
    2. Go to GameObject > Create Empty and name the new game object PresentationManager.
    3. In your Assets/Scripts directory, create a new script and name it PresentationManager.
    4. Attach the PresentationManager script to your PresentationManager game object.
    5. In your PresentationManager script file, use the PresentationManager class to do the following:

      • Reference an IPresentationService and an ISessionProvider
      • 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;
        }
        
    6. Use the Awake method to retrieve services from PlatformServices and to subscribe to the SessionChanged event. Use the OnDestroy method 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;
       }
      
    7. Use the OnSessionChanged method 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;
           }
       }
      
    8. Use the OnJoinClickAsync method 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:

    1. In your scene, create a text field to display information about the presentation mode.
    2. In your Assets/Scripts directory, create a new script and name it PresentationTextUpdater.
    3. Attach the PresentationTextUpdater script to your PresentationManager game object.
    4. In your PresentationTextUpdater script file, use the PresentationTextUpdater class to reference an IPresentationService and your text field.

       public class PresentationTextUpdater : MonoBehaviour
       {
           IPresentationService m_PresentationService;
      
           [SerializeField]
           Text m_TextField;
       }
      
    5. Use the Awake method to retrieve services from PlatformServices and to subscribe to the PresentationEvent event. Use the OnDestroy method to unsubscribe from the event.

       void Awake()
       {
           m_PresentationService = PlatformServices.PresentationService;
           m_PresentationService.PresentationEvent += OnPresentationEvent;
       }
      
       void OnDestroy()
       {
           m_PresentationService.PresentationEvent -= OnPresentationEvent;
       }
      
    6. Use the OnPresentationEvent method 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();
       }
      
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023