using System; using System.Collections.Generic; using UnityEngine.XR.ARSubsystems; namespace UnityEngine.XR.ARFoundation { /// /// A manager for s. Creates, updates, and removes /// GameObjects in response to other users in a multi-user collaborative session. /// [DefaultExecutionOrder(ARUpdateOrder.k_ParticipantManager)] [DisallowMultipleComponent] [RequireComponent(typeof(ARSessionOrigin))] [HelpURL(HelpUrls.ApiWithNamespace + nameof(ARParticipantManager) + ".html")] public sealed class ARParticipantManager : ARTrackableManager< XRParticipantSubsystem, XRParticipantSubsystemDescriptor, XRParticipantSubsystem.Provider, XRParticipant, ARParticipant> { [SerializeField] [Tooltip("(Optional) Instantiates this prefab for each participant.")] GameObject m_ParticipantPrefab; /// /// (Optional) Instantiates this Prefab for each participant. If null, an empty GameObject /// with a component is instantiated instead. /// public GameObject participantPrefab { get => m_ParticipantPrefab; set => m_ParticipantPrefab = value; } /// /// Invoked when participants have changed (been added, updated, or removed). /// public event Action participantsChanged; /// /// Attempt to retrieve an existing by . /// /// The of the participant to retrieve. /// The with , or null if it does not exist. public ARParticipant GetParticipant(TrackableId trackableId) { if (m_Trackables.TryGetValue(trackableId, out ARParticipant participant)) return participant; return null; } /// /// The Prefab which will be instantiated for each . Can be `null`. /// /// A Prefab to instantiate for each . protected override GameObject GetPrefab() => m_ParticipantPrefab; /// /// Invoked when the base class detects trackable changes. /// /// The list of added s. /// The list of updated s. /// The list of removed s. protected override void OnTrackablesChanged( List added, List updated, List removed) { if (participantsChanged != null) { using (new ScopedProfiler("OnParticipantsChanged")) participantsChanged( new ARParticipantsChangedEventArgs( added, updated, removed)); } } /// /// The name to be used for the GameObject whenever a new participant is detected. /// protected override string gameObjectName => "ARParticipant"; } }