using System; using System.Collections.Generic; using UnityEngine.XR.Interaction.Toolkit.Filtering; namespace UnityEngine.XR.Interaction.Toolkit.Utilities { /// /// /// /// Should be an interface. /// /// /// /// A small registration list that can be exposed to users through the public interface . /// /// class ExposedRegistrationList : SmallRegistrationList, IXRFilterList where T : class { public int count => flushedCount; public void Add(T item) { if (item == null || (item is Object unityObj && unityObj == null)) throw new ArgumentNullException(nameof(item)); Register(item); } public bool Remove(T item) => Unregister(item); public void MoveTo(T item, int newIndex) => MoveItemImmediately(item, newIndex); public void Clear() => UnregisterAll(); public void GetAll(List results) => GetRegisteredItems(results); public T GetAt(int index) => GetRegisteredItemAt(index); /// /// Register the given in this registration list. /// /// The list of items to add to the end of this list. /// (Optional) the object context, ony used when an error needs to be thrown in the Console window. /// The references type. /// /// If an element in the does not implement the interface , /// an error is thrown in the Console window. /// /// public void RegisterReferences(List references, Object context = null) where TObject : Object { foreach (var reference in references) { if (reference != null && reference is T item) Add(item); else if (context != null) Debug.LogError($"Trying to add the invalid item {reference} into {typeof(IXRFilterList).Name}, in {context}. {reference} does not implement {typeof(T).Name}.", context); else Debug.LogError($"Trying to add the invalid item {reference} into {typeof(IXRFilterList).Name}. {reference} does not implement {typeof(T).Name}."); } } } }