Пример #1
0
        public static ICompletable BindAsCompletable(this IBinder This, string source, Image target, bool isOptional = false,
                                                     Loadzup.Options options = null,
                                                     bool keepVisible        = false, float?fadeDuration = null, bool isPriority = false)
        {
            if (source == null || target == null)
            {
                return(Completable.Empty());
            }

            return(This.BindAsCompletable(new Uri(source), target, isOptional, options, keepVisible, fadeDuration, isPriority));
        }
Пример #2
0
        // ReSharper disable once UnusedParameter.Global
        public static ICompletable BindAsCompletable(this IBinder This, object source, IPresenter target)
        {
            if (source == null || target == null)
            {
                return(Completable.Empty());
            }

            return(target
                   .Present(source)
                   .AutoDetach()
                   .AsCompletable());
        }
Пример #3
0
            public ICompletable Load()
            {
                if (IsCancelled)
                {
                    _subject.Dispose();
                    return(Completable.Empty());
                }

                return(_loadRequest
                       .Do(_subject.OnNext, _subject.OnError, _subject.OnCompleted)
                       .CatchIgnore()
                       .AsCompletable());
            }
Пример #4
0
 private ICompletable LoadLoadable(IView view)
 {
     try
     {
         return((view as ILoadable)?.Load()?
                .Catch <Exception>(ex =>
                                   Completable.Throw(new LoadException($"Error in view.Load() of {view.GetType().Name}", ex)))
                ?? Completable.Empty());
     }
     catch (Exception ex)
     {
         return(Completable.Throw(new LoadException($"Error in view.Load() of {view.GetType().Name}", ex)));
     }
 }
Пример #5
0
        protected ICompletable CancellationPoint()
        {
            if (Presentation.CancellationToken.IsCancellationRequested)
            {
                _performers
                .Where(x => x.State == PhaseState.Started)
                .Reverse()
                .ForEach(x => x.Cancel());

                return(Completable.Throw(new PhaseCancelledException()));
            }

            return(Completable.Empty());
        }
Пример #6
0
        protected override ICompletable Present(Presentation presentation)
        {
            if (Container == null)
            {
                throw new InvalidOperationException($"Must specify ContentContainer property of ContentControl {gameObject}");
            }

            var sourceView = presentation.SourceView;
            var targetView = presentation.TargetView;
            var options    = presentation.Options;

            PreHide(sourceView, options);
            PreShow(targetView, options);

            ReplaceView(Container, targetView);
            _view.Value = targetView;

            PostHide(sourceView, options);
            PostShow(targetView, options);

            return(Completable.Empty());
        }
Пример #7
0
 public override ICompletable Perform(GameObject sourceContainer, GameObject targetContainer,
                                      Direction direction, float duration) => Completable.Empty();
Пример #8
0
        public static ICompletable BindAsCompletable(this IBinder This, RawImage image, Uri uri, bool isOptional = false,
                                                     Loadzup.Options options = null, bool keepVisible = false, float?fadeDuration = null, bool isPriority = false)
        {
            if (image == null)
            {
                return(Completable.Empty());
            }

            if (uri == null)
            {
                if (isOptional)
                {
                    return(Completable.Empty());
                }

                return(Completable.Throw(
                           new BindException(
                               $"Cannot bind required image {image.gameObject.name} in view {This.View.GameObject.name} to null Uri.")));
            }

            if (fadeDuration != null)
            {
                image.color = Color.clear;
            }
            else
            {
                image.enabled = keepVisible;
            }

            return(This.Loader
                   .With(This.DefaultImageHttpCachePolicy)
                   .WithCancellationOnDestroy(This.View)
                   .WithQueuing(isPriority)
                   .Load <Texture2D>(uri, options)
                   .Catch <Texture2D, Exception>(ex => Observable
                                                 .Throw <Texture2D>(new BindException(
                                                                        $"Failed to load image {image.gameObject.name} in view {This.View.GetType().Name} from {uri}", ex)))
                   .Do(x =>
            {
                if (image.IsDestroyed())
                {
                    if (uri.Scheme == Scheme.Http || uri.Scheme == Scheme.Https ||
                        uri.Scheme == Scheme.StreamingAsset || uri.Scheme == Scheme.StreamingFile)
                    {
                        Object.Destroy(x);
                    }
                    return;
                }

                image.texture = x;
                image.enabled = true;

                if (fadeDuration != null)
                {
                    Observable.NextFrame()
                    .Then(_ => image.TweenColorTo(Color.white, fadeDuration.Value))
                    .SubscribeAndForget()
                    .AddTo(This);
                }

                if (uri.Scheme == Scheme.Http || uri.Scheme == Scheme.Https ||
                    uri.Scheme == Scheme.StreamingAsset || uri.Scheme == Scheme.StreamingFile)
                {
                    Disposable
                    .Create(() => Object.Destroy(x))
                    .AddTo(This);
                }
            })
                   .AutoDetach()
                   .AsCompletable());
        }
Пример #9
0
        public static ICompletable BindAsCompletable(this IBinder This, Uri source, Image target, bool isOptional = false,
                                                     Loadzup.Options options = null,
                                                     bool keepVisible        = false, float?fadeDuration = null, bool isPriority = false)
        {
            if (target == null)
            {
                return(Completable.Empty());
            }

            if (source == null)
            {
                if (isOptional)
                {
                    return(Completable.Empty());
                }

                return(Completable.Throw(
                           new BindException(
                               $"Cannot bind required image {target.gameObject.name} in view {This.View.GameObject.name} to null Uri.")));
            }

            if (fadeDuration != null)
            {
                target.color = Color.clear;
            }
            else
            {
                target.enabled = keepVisible;
            }

            return(This.Loader
                   .With(This.DefaultImageHttpCachePolicy)
                   .WithCancellationOnDestroy(This.View)
                   .WithQueuing(isPriority)
                   .Load <DisposableSprite>(source, options)
                   .Catch <DisposableSprite, Exception>(ex =>
                                                        Observable.Throw <DisposableSprite>(
                                                            new BindException(
                                                                $"Failed to load image {target.gameObject.name} in view {This.View.GetType().Name} from {source}", ex)))
                   .Do(x =>
            {
                if (target.IsDestroyed())
                {
                    if (source.Scheme == Scheme.Http || source.Scheme == Scheme.Https ||
                        source.Scheme == Scheme.StreamingAsset || source.Scheme == Scheme.StreamingFile)
                    {
                        x.Dispose();
                    }
                    return;
                }

                target.sprite = x.Sprite;
                target.enabled = true;

                if (fadeDuration != null)
                {
                    Observable.NextFrame()
                    .Then(_ => target.TweenColorTo(Color.white, fadeDuration.Value))
                    .SubscribeAndForget()
                    .AddTo(This);
                }

                if (source.Scheme == Scheme.Http || source.Scheme == Scheme.Https || source.Scheme == Scheme.StreamingAsset ||
                    source.Scheme == Scheme.StreamingFile)
                {
                    x.AddTo(This);
                }
            })
                   .AutoDetach()
                   .AsCompletable());
        }