public static IDisposable RegisterDefaultAdditionalInfo(Func <IDisposable> a)
        {
            var previous = addAdditionalInfo;

            addAdditionalInfo = a;
            return(Disposables.Create(() => addAdditionalInfo = previous));
        }
        public void TestDisposable()
        {
            var callCount = 1;

            // begin-snippet: disposables
            using (var cleanup = Disposables.Create(() => callCount++))
            {
                //code
            }
            // end-snippet

            Assert.Equal(2, callCount);
        }
Beispiel #3
0
            public static IDisposable LeftMouseClick(IList <GameObject> items, Action <int> selectItem)
            {
                var disposeListeners = new CompositeDisposable();

                for (int i = 0; i < items.Count; i++)
                {
                    var    itemIndex   = i;
                    var    item        = items[i];
                    var    mouseEvents = item.GetComponent <UIEventSource>();
                    Action select      = () => selectItem(itemIndex);
                    mouseEvents.OnCursorClick += select;
                    disposeListeners.Add(Disposables.Create(() => mouseEvents.OnCursorEnter -= select));
                }
                return(disposeListeners);
            }
Beispiel #4
0
            private static IDisposable AddMouseHighlight(Action <int?> updateHighlightedIndex, IList <GameObject> items)
            {
                var disposeListeners = new CompositeDisposable();

                for (int i = 0; i < items.Count; i++)
                {
                    var itemIndex   = i;
                    var item        = items[i];
                    var mouseEvents = item.GetComponent <UIEventSource>();

                    Action highlight = () => updateHighlightedIndex(itemIndex);
                    mouseEvents.OnCursorEnter += highlight;
                    disposeListeners.Add(Disposables.Create(() => mouseEvents.OnCursorEnter -= highlight));
                }
                return(disposeListeners);
            }