private void Awake() { _adService .AdsLoaded .Select(adLoaded => RxExtensions.FromAsync(token => SetButtonAvailability(adLoaded, token))) .Switch() .Subscribe() .AddTo(this); button .onClick .AsObservable() .Subscribe(x => levelDataModel.SkipLevel()) .AddTo(this); }
public LoadingViewModel( IScreen hostScreen = null, IAppSettings appSettings = null ) : base(hostScreen) { _appSettings = appSettings ?? Locator.Current.GetService <IAppSettings>(); LoadCommand = ReactiveCommand.CreateFromTask(LoadStuff); RxExtensions.Signal() .InvokeCommand(LoadCommand); _isLoading = LoadCommand.IsExecuting .ToProperty(this, vm => vm.IsLoading); LoadCommand.Subscribe(); }
protected override void Start() { base.Start(); back.onClick.AddListener(MainUi.ShowMain); CurrentPageState .Where(state => state == PageState.Open) .Select(state => RxExtensions.FromAsync(CreateViews)) .Switch() .CombineWithPrevious((previous, next) => (previous, next)) .Select(combination => OnChangeLevelViews(combination.previous, combination.next)) .Select(icon => RxExtensions.FromAsync(async token => { if (icon != default) { await scrollRect .GetSnapToPositionToBringChildIntoView(icon.RectTransform, 0.6f) .ToUniTask(cancellationToken: token); } })) .Switch() .Subscribe() .AddTo(this); }
/// <summary> /// 以观察模式发送请求。 /// </summary> /// <typeparam name="T">返回值类型。</typeparam> /// <param name="functionAsync">执行请求的函数。</param> /// <returns>返回 <see cref="RxExtensions.Wrapper{T}"/> 类的新实例。</returns> /******************************************************************* * * var client = new HearFromsClient(); * * // 异步调用,不等待。 * client.Observable(() => client.GetAsync(Guid.Empty)) * .WaitAndRetry( * TimeSpan.FromSeconds(10), * TimeSpan.FromSeconds(20), * TimeSpan.FromSeconds(30) * ).Subscribe(details => * { * var d = details; * }, ex => * { * var c = (ex as SwaggerException); * Console.WriteLine($"{c.Message}({c.StatusCode})"); * }); * * // 同步调用,等待。 * client.Observable(() => client.GetAsync(Guid.Empty)) * .WaitAndRetry( * TimeSpan.FromSeconds(1), * TimeSpan.FromSeconds(3), * TimeSpan.FromSeconds(5) * ).Execute(details => * { * var d = details; * }, ex => * { * Console.WriteLine(ex.Message); * var c = (ex as SwaggerException); * Console.WriteLine($"{c?.Message}({c?.StatusCode})"); * }); * *******************************************************************/ public RxExtensions.Wrapper <T> Observable <T>(Func <Task <T> > functionAsync) { return(RxExtensions.Observable(functionAsync)); }