using System;
using System.Collections.Generic;
using UnityEngine.XR.ARSubsystems;
using Unity.XR.CoreUtils;
namespace UnityEngine.XR.ARFoundation
{
///
/// A manager for s. Creates, updates, and removes
/// GameObjects in response to other users in a multi-user collaborative session.
///
///
/// Related information: AR Participant Manager component
///
[DefaultExecutionOrder(ARUpdateOrder.k_ParticipantManager)]
[DisallowMultipleComponent]
[RequireComponent(typeof(XROrigin))]
[AddComponentMenu("XR/AR Foundation/AR Participant Manager")]
[HelpURL("features/participant-tracking")]
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).
///
[Obsolete("participantsChanged has been deprecated in AR Foundation version 6.0. Use trackablesChanged instead.", false)]
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.
[Obsolete("OnTrackablesChanged() has been deprecated in AR Foundation version 6.0.", false)]
protected override void OnTrackablesChanged(
List added,
List updated,
List removed)
{
if (participantsChanged != null)
{
using (new ScopedProfiler("OnParticipantsChanged"))
participantsChanged?.Invoke(
new ARParticipantsChangedEventArgs(
added,
updated,
removed));
}
}
///
/// The name to be used for the GameObject whenever a new participant is detected.
///
protected override string gameObjectName => "ARParticipant";
}
}