A game about forced loneliness, made by TACStudios
1#if UNITY_EDITOR 2using System.Collections; 3using System.Collections.Generic; 4using System.Linq; 5 6namespace UnityEngine.InputSystem.Editor 7{ 8 /// <summary> 9 /// A caching enumerator that will save all enumerated values on the first iteration, and when 10 /// subsequently iterated, return the saved values instead. 11 /// </summary> 12 /// <typeparam name="T"></typeparam> 13 internal class ViewStateCollection<T> : IViewStateCollection, IEnumerable<T> 14 { 15 private readonly IEnumerable<T> m_Collection; 16 private readonly IEqualityComparer<T> m_Comparer; 17 private IList<T> m_CachedCollection; 18 19 public ViewStateCollection(IEnumerable<T> collection, IEqualityComparer<T> comparer = null) 20 { 21 m_Collection = collection; 22 m_Comparer = comparer; 23 } 24 25 public bool SequenceEqual(IViewStateCollection other) 26 { 27 return other is ViewStateCollection<T> otherCollection && this.SequenceEqual(otherCollection, m_Comparer); 28 } 29 30 public IEnumerator<T> GetEnumerator() 31 { 32 if (m_CachedCollection == null) 33 { 34 m_CachedCollection = new List<T>(); 35 using (var enumerator = m_Collection.GetEnumerator()) 36 { 37 while (enumerator.MoveNext()) 38 { 39 m_CachedCollection.Add(enumerator.Current); 40 } 41 } 42 } 43 44 using (var enumerator = m_CachedCollection.GetEnumerator()) 45 { 46 while (enumerator.MoveNext()) 47 yield return enumerator.Current; 48 } 49 } 50 51 IEnumerator IEnumerable.GetEnumerator() 52 { 53 return GetEnumerator(); 54 } 55 } 56} 57 58#endif