#if UNITY_EDITOR using System.Collections; using System.Collections.Generic; using System.Linq; namespace UnityEngine.InputSystem.Editor { /// /// A caching enumerator that will save all enumerated values on the first iteration, and when /// subsequently iterated, return the saved values instead. /// /// internal class ViewStateCollection : IViewStateCollection, IEnumerable { private readonly IEnumerable m_Collection; private readonly IEqualityComparer m_Comparer; private IList m_CachedCollection; public ViewStateCollection(IEnumerable collection, IEqualityComparer comparer = null) { m_Collection = collection; m_Comparer = comparer; } public bool SequenceEqual(IViewStateCollection other) { return other is ViewStateCollection otherCollection && this.SequenceEqual(otherCollection, m_Comparer); } public IEnumerator GetEnumerator() { if (m_CachedCollection == null) { m_CachedCollection = new List(); using (var enumerator = m_Collection.GetEnumerator()) { while (enumerator.MoveNext()) { m_CachedCollection.Add(enumerator.Current); } } } using (var enumerator = m_CachedCollection.GetEnumerator()) { while (enumerator.MoveNext()) yield return enumerator.Current; } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } } #endif