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("https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@3.0/api/UnityEngine.XR.ARFoundation.ARParticipantManager.html")] public sealed class ARParticipantManager : ARTrackableManager< XRParticipantSubsystem, XRParticipantSubsystemDescriptor, 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 { return 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; } protected override GameObject GetPrefab() { return m_ParticipantPrefab; } protected override void OnTrackablesChanged( List added, List updated, List removed) { if (participantsChanged != null) { participantsChanged( new ARParticipantsChangedEventArgs( added, updated, removed)); } } /// /// The name to be used for the GameObject whenever a new participant is detected. /// protected override string gameObjectName { get { return "ARParticipant"; } } } }