Exemplo n.º 1
0
        public static UniRx.IObservable <TProperty> ObserveEveryValueChanged <TSource, TProperty>(this TSource source, Func <TSource, TProperty> propertySelector, FrameCountType frameCountType, IEqualityComparer <TProperty> comparer, bool fastDestroyCheck) where TSource : class
        {
            if (source == null)
            {
                return(Observable.Empty <TProperty>());
            }
            if (comparer == null)
            {
                comparer = UnityEqualityComparer.GetDefault <TProperty>();
            }
            UnityEngine.Object unityObject = source as UnityEngine.Object;
            bool flag = source is UnityEngine.Object;

            if (flag && unityObject == null)
            {
                return(Observable.Empty <TProperty>());
            }
            if (flag)
            {
                return(Observable.FromMicroCoroutine(delegate(UniRx.IObserver <TProperty> observer, CancellationToken cancellationToken)
                {
                    if (unityObject != null)
                    {
                        TProperty val2 = default(TProperty);
                        try
                        {
                            val2 = propertySelector((TSource)(object)unityObject);
                        }
                        catch (Exception error2)
                        {
                            observer.OnError(error2);
                            return EmptyEnumerator();
                        }
                        observer.OnNext(val2);
                        return PublishUnityObjectValueChanged(unityObject, val2, propertySelector, comparer, observer, cancellationToken, fastDestroyCheck);
                    }
                    observer.OnCompleted();
                    return EmptyEnumerator();
                }, frameCountType));
            }
            WeakReference reference = new WeakReference(source);

            source = (TSource)null;
            return(Observable.FromMicroCoroutine(delegate(UniRx.IObserver <TProperty> observer, CancellationToken cancellationToken)
            {
                object target = reference.Target;
                if (target != null)
                {
                    TProperty val = default(TProperty);
                    try
                    {
                        val = propertySelector((TSource)target);
                    }
                    catch (Exception error)
                    {
                        observer.OnError(error);
                        return EmptyEnumerator();
                    }
                    finally
                    {
                        target = null;
                    }
                    observer.OnNext(val);
                    return PublishPocoValueChanged(reference, val, propertySelector, comparer, observer, cancellationToken);
                }
                observer.OnCompleted();
                return EmptyEnumerator();
            }, frameCountType));
        }