ARParticipantsChangedEventArgs.cs
4.61 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
90
91
92
93
94
95
using System;
using System.Collections.Generic;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// Event arguments for the <see cref="ARParticipantManager.participantsChanged"/> event.
/// </summary>
public struct ARParticipantsChangedEventArgs : IEquatable<ARParticipantsChangedEventArgs>
{
/// <summary>
/// The list of <see cref="ARParticipant"/>s added since the last event.
/// </summary>
public List<ARParticipant> added { get; private set; }
/// <summary>
/// The list of <see cref="ARParticipant"/>s udpated since the last event.
/// </summary>
public List<ARParticipant> updated { get; private set; }
/// <summary>
/// The list of <see cref="ARParticipant"/>s removed since the last event.
/// </summary>
public List<ARParticipant> removed { get; private set; }
/// <summary>
/// Constructs an <see cref="ARParticipantsChangedEventArgs"/>.
/// </summary>
/// <param name="added">The list of <see cref="ARParticipant"/>s added since the last event.</param>
/// <param name="updated">The list of <see cref="ARParticipant"/>s updated since the last event.</param>
/// <param name="removed">The list of <see cref="ARParticipant"/>s removed since the last event.</param>
public ARParticipantsChangedEventArgs(
List<ARParticipant> added,
List<ARParticipant> updated,
List<ARParticipant> removed)
{
this.added = added;
this.updated = updated;
this.removed = removed;
}
/// <summary>
/// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`.
/// </summary>
/// <returns>A hash code generated from this object's fields.</returns>
public override int GetHashCode() => HashCode.Combine(
HashCode.ReferenceHash(added),
HashCode.ReferenceHash(updated),
HashCode.ReferenceHash(removed));
/// <summary>
/// Tests for equality.
/// </summary>
/// <param name="obj">The `object` to compare against.</param>
/// <returns>`True` if <paramref name="obj"/> is of type <see cref="ARParticipantsChangedEventArgs"/> and
/// <see cref="Equals(ARParticipantsChangedEventArgs)"/> also returns `true`; otherwise `false`.</returns>
public override bool Equals(object obj) => (obj is ARParticipantsChangedEventArgs) && Equals((ARParticipantsChangedEventArgs)obj);
int GetCount(List<ARParticipant> list) => list != null ? list.Count : 0;
/// <summary>
/// Generates a string suitable for debugging. The string contains the number of added, updated, and removed participants.
/// </summary>
/// <returns>A string suitable for debug logging.</returns>
public override string ToString() => $"Added: {GetCount(added)}, Updated: {GetCount(updated)}, Removed: {GetCount(removed)}";
/// <summary>
/// Tests for equality.
/// </summary>
/// <param name="other">The other <see cref="ARParticipantsChangedEventArgs"/> to compare against.</param>
/// <returns><c>true</c> if <paramref name="other"/> is equal to this <see cref="ARParticipantsChangedEventArgs"/>.</returns>
public bool Equals(ARParticipantsChangedEventArgs other)
{
return
ReferenceEquals(added, other.added) &&
ReferenceEquals(updated, other.updated) &&
ReferenceEquals(removed, other.removed);
}
/// <summary>
/// Tests for equality. Same as <see cref="Equals(ARParticipantsChangedEventArgs)"/>.
/// </summary>
/// <param name="lhs">The left-hand side of the comparison.</param>
/// <param name="rhs">The right-hand side of the comparison.</param>
/// <returns><c>true</c> if <paramref name="lhs"/> is equal to <paramref name="rhs"/>.</returns>
public static bool operator ==(ARParticipantsChangedEventArgs lhs, ARParticipantsChangedEventArgs rhs) => lhs.Equals(rhs);
/// <summary>
/// Tests for inequality. Same as <c>!</c><see cref="Equals(ARParticipantsChangedEventArgs)"/>.
/// </summary>
/// <param name="lhs">The left-hand side of the comparison.</param>
/// <param name="rhs">The right-hand side of the comparison.</param>
/// <returns><c>true</c> if <paramref name="lhs"/> is not equal to <paramref name="rhs"/>.</returns>
public static bool operator !=(ARParticipantsChangedEventArgs lhs, ARParticipantsChangedEventArgs rhs) => !lhs.Equals(rhs);
}
}