ARParticipantManager.cs
3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// A manager for <see cref="ARParticipant"/>s. Creates, updates, and removes
/// <c>GameObject</c>s in response to other users in a multi-user collaborative session.
/// </summary>
[DefaultExecutionOrder(ARUpdateOrder.k_ParticipantManager)]
[DisallowMultipleComponent]
[RequireComponent(typeof(ARSessionOrigin))]
[HelpURL(HelpUrls.ApiWithNamespace + nameof(ARParticipantManager) + ".html")]
public sealed class ARParticipantManager : ARTrackableManager<
XRParticipantSubsystem,
XRParticipantSubsystemDescriptor,
#if UNITY_2020_2_OR_NEWER
XRParticipantSubsystem.Provider,
#endif
XRParticipant,
ARParticipant>
{
[SerializeField]
[Tooltip("(Optional) Instantiates this prefab for each participant.")]
GameObject m_ParticipantPrefab;
/// <summary>
/// (Optional) Instantiates this prefab for each participant. If <c>null</c>, an empty <c>GameObject</c>
/// with a <see cref="ARParticipant"/> component is instantiated instead.
/// </summary>
public GameObject participantPrefab
{
get => m_ParticipantPrefab;
set => m_ParticipantPrefab = value;
}
/// <summary>
/// Invoked when participants have changed (been added, updated, or removed).
/// </summary>
public event Action<ARParticipantsChangedEventArgs> participantsChanged;
/// <summary>
/// Attempt to retrieve an existing <see cref="ARParticipant"/> by <paramref name="trackableId"/>.
/// </summary>
/// <param name="trackableId">The <see cref="TrackableId"/> of the participant to retrieve.</param>
/// <returns>The <see cref="ARParticipant"/> with <paramref name="trackableId"/>, or <c>null</c> if it does not exist.</returns>
public ARParticipant GetParticipant(TrackableId trackableId)
{
if (m_Trackables.TryGetValue(trackableId, out ARParticipant participant))
return participant;
return null;
}
/// <summary>
/// The prefab which will be instantiated for each <see cref="ARParticipant"/>. May be `null`.
/// </summary>
/// <returns>A prefab to instantiate for each <see cref="ARParticipant"/>.</returns>
protected override GameObject GetPrefab() => m_ParticipantPrefab;
/// <summary>
/// Invoked when the base class detects trackable changes.
/// </summary>
/// <param name="added">The list of added <see cref="ARParticipant"/>s.</param>
/// <param name="updated">The list of updated <see cref="ARParticipant"/>s.</param>
/// <param name="removed">The list of removed <see cref="ARParticipant"/>s.</param>
protected override void OnTrackablesChanged(
List<ARParticipant> added,
List<ARParticipant> updated,
List<ARParticipant> removed)
{
if (participantsChanged != null)
{
using (new ScopedProfiler("OnParticipantsChanged"))
participantsChanged(
new ARParticipantsChangedEventArgs(
added,
updated,
removed));
}
}
/// <summary>
/// The name to be used for the <c>GameObject</c> whenever a new participant is detected.
/// </summary>
protected override string gameObjectName => "ARParticipant";
}
}