using System; namespace UnityEngine.InputSystem.Utilities { internal class TakeNObservable : IObservable { private IObservable m_Source; private int m_Count; public TakeNObservable(IObservable source, int count) { m_Source = source; m_Count = count; } public IDisposable Subscribe(IObserver observer) { return m_Source.Subscribe(new Take(this, observer)); } private class Take : IObserver { private IObserver m_Observer; private int m_Remaining; public Take(TakeNObservable observable, IObserver observer) { m_Observer = observer; m_Remaining = observable.m_Count; } public void OnCompleted() { } public void OnError(Exception error) { Debug.LogException(error); } public void OnNext(TValue evt) { if (m_Remaining <= 0) return; m_Remaining--; m_Observer.OnNext(evt); if (m_Remaining == 0) { m_Observer.OnCompleted(); m_Observer = default; } } } } }