using System;
using System.Collections.Generic;
using Unity.XR.CoreUtils.Collections;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARFoundation
{
///
/// Event arguments for the `ARTrackableManager.trackablesChanged` event.
///
/// The trackable type.
public readonly struct ARTrackablesChangedEventArgs : IEquatable>
where TTrackable : ARTrackable
{
///
/// The collection of trackables that have been added.
///
public ReadOnlyList added { get; }
///
/// The collection of trackables that have been updated.
///
public ReadOnlyList updated { get; }
///
/// The collection of trackables that have been removed.
///
public ReadOnlyList> removed { get; }
///
/// Constructs an .
///
/// The collection of trackables that have been added.
/// The collection of trackables that have been updated.
/// The collection of trackables that have been removed.
public ARTrackablesChangedEventArgs(
ReadOnlyList added,
ReadOnlyList updated,
ReadOnlyList> removed)
{
this.added = added ?? new ReadOnlyList(new List(0));
this.updated = updated ?? new ReadOnlyList(new List(0));
this.removed = removed ?? new ReadOnlyList>(
new List>(0));
}
///
/// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`.
///
/// A hash code generated from this object's fields.
public override int GetHashCode() => HashCodeUtil.Combine(
HashCodeUtil.ReferenceHash(added),
HashCodeUtil.ReferenceHash(updated),
HashCodeUtil.ReferenceHash(removed));
///
/// Tests for equality.
///
/// The `object` to compare against.
/// Returns if is of type
/// and
/// also returns .
/// Otherwise, returns .
public override bool Equals(object obj)
{
return obj is ARTrackablesChangedEventArgs args && Equals(args);
}
///
/// Generates a string representation of this .
///
/// A string representation of this .
public override string ToString()
{
return $"Added: {added?.Count ?? 0}, Updated: {updated?.Count ?? 0}, Removed: {removed?.Count ?? 0}";
}
///
/// Tests for equality.
///
/// The other to compare against.
/// Returns if every field in is equal to this
/// , otherwise returns .
public bool Equals(ARTrackablesChangedEventArgs other)
{
return
added == other.added &&
updated == other.updated &&
removed == other.removed;
}
///
/// Tests for equality. Same as .
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// Returns if is equal to .
/// Otherwise, returns .
public static bool operator ==(ARTrackablesChangedEventArgs lhs, ARTrackablesChangedEventArgs rhs)
{
return lhs.Equals(rhs);
}
///
/// Tests for inequality. Same as `!`.
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// Returns if is not equal to .
/// Otherwise, returns .
public static bool operator !=(ARTrackablesChangedEventArgs lhs, ARTrackablesChangedEventArgs rhs)
{
return !lhs.Equals(rhs);
}
}
}