Ejemplo n.º 1
0
        private IEnumerator SendReport()
        {
            var sendReportManager = SendReportManager.Instance;

            UpdatePostProgress(0f);

            yield return(CaptureScreenShot());

            yield return(new WaitForEndOfFrame());

            // 進捗.
            var notifier = new ScheduledNotifier <float>();

            notifier.Subscribe(x => UpdatePostProgress(x));

            var sendYield = sendReportManager.Send(ReportTitle, notifier).ToYieldInstruction(false);

            while (!sendYield.IsDone)
            {
                yield return(null);
            }

            if (sendYield.HasError)
            {
                Debug.LogException(sendYield.Error);
            }
        }
Ejemplo n.º 2
0
        void Start()
        {
            //Resources.LoadAsync<GameObject>("TestCanvas").AsAsyncOperationObservable()
            //        .Subscribe(resourceRequest =>
            //        {
            //            Debug.Log(resourceRequest.ToString());
            //            Debug.Log(resourceRequest.asset.ToString());
            //            Instantiate(resourceRequest.asset);
            //        });
            var progressObservable = new ScheduledNotifier <float>();      //プログレスバーの構成  Progress bar

            var mslider = transform.Find("Slider").GetComponent <Slider>();


            SceneManager.LoadSceneAsync(0).AsAsyncOperationObservable(progressObservable)
            .Subscribe(_ =>
            {
                Debug.Log("load done");                  //ロード完了
            });

            progressObservable
            .Subscribe(progress =>
            {
                Debug.LogFormat("完成:{0}%", progress * 100);
                mslider.value = progress + 0.1f;
                mtext.text    = progress * 100 + 10 + "%";
            })
            .AddTo(this);
        }
        public void CancelTest()
        {
            var testScheduler = new TestScheduler();
            var recorder      = testScheduler.CreateObserver <int>();

            var notifier = new ScheduledNotifier <int>(testScheduler);

            notifier.Subscribe(recorder);

            var noCancel1 = notifier.Report(10, TimeSpan.FromMinutes(1));
            var cancel1   = notifier.Report(20, TimeSpan.FromMinutes(3));

            cancel1.Dispose();

            recorder.Messages.Count.Is(0);
            testScheduler.AdvanceBy(TimeSpan.FromMinutes(5).Ticks);
            recorder.Messages.Count.Is(1);
            recorder.Messages[0].Is(OnNext(TimeSpan.FromMinutes(1).Ticks, 10));

            var lastTime = recorder.Messages.Last().Time;

            recorder.Messages.Clear();

            var origin    = new DateTimeOffset(1999, 1, 1, 1, 1, 1, TimeSpan.Zero);
            var noCancel2 = notifier.Report(30, origin.AddMinutes(1));
            var cancel2   = notifier.Report(40, origin.AddMinutes(3));

            cancel2.Dispose();

            testScheduler.AdvanceTo(origin.AddMinutes(5).Ticks);
            recorder.Messages.Is(
                OnNext(origin.AddMinutes(1).Ticks, 30));
        }
        public void TestOffset()
        {
            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<int>();

            var notifier = new ScheduledNotifier<int>(testScheduler);
            notifier.Subscribe(recorder);

            var origin = new DateTimeOffset(1999, 1, 1, 1, 1, 1, TimeSpan.Zero);

            notifier.Report(1);
            notifier.Report(2);
            notifier.Report(3, origin);
            notifier.Report(4, origin.AddDays(10));
            notifier.Report(5, origin.AddYears(1));
            notifier.Report(6);

            testScheduler.Start();

            recorder.Messages.Is(
                OnNext(1, 1),
                OnNext(1, 2),
                OnNext(1, 6),
                OnNext(origin.Ticks, 3),
                OnNext(origin.AddDays(10).Ticks, 4),
                OnNext(origin.AddYears(1).Ticks, 5));
        }
        public AsynchronousViewModel()
        {
            // Notifier of network connecitng status/count
            var connect = new CountNotifier();
            // Notifier of network progress report
            var progress = new ScheduledNotifier<Tuple<long, long>>(); // current, total

            // skip initialValue on subscribe
            SearchTerm = new ReactiveProperty<string>(mode: ReactivePropertyMode.DistinctUntilChanged);

            // Search asynchronous & result direct bind
            // if network error, use OnErroRetry
            // that catch exception and do action and resubscript.
            SearchResults = SearchTerm
                .Select(async term =>
                {
                    using (connect.Increment()) // network open
                    {
                        return await WikipediaModel.SearchTermAsync(term, progress);
                    }
                })
                .Switch() // flatten
                .OnErrorRetry((HttpRequestException ex) => ProgressStatus.Value = "error occured")
                .ToReactiveProperty();

            // CountChangedStatus : Increment(network open), Decrement(network close), Empty(all complete)
            SearchingStatus = connect
                .Select(x => (x != CountChangedStatus.Empty) ? "loading..." : "complete")
                .ToReactiveProperty();

            ProgressStatus = progress
                .Select(x => string.Format("{0}/{1} {2}%", x.Item1, x.Item2, ((double)x.Item1 / x.Item2) * 100))
                .ToReactiveProperty();
        }
Ejemplo n.º 6
0
        public AsynchronousViewModel()
        {
            // Notifier of network connecitng status/count
            var connect = new CountNotifier();
            // Notifier of network progress report
            var progress = new ScheduledNotifier <Tuple <long, long> >(); // current, total

            // skip initialValue on subscribe
            SearchTerm = new ReactiveProperty <string>(mode: ReactivePropertyMode.DistinctUntilChanged);

            // Search asynchronous & result direct bind
            // if network error, use OnErroRetry
            // that catch exception and do action and resubscript.
            SearchResults = SearchTerm
                            .Select(async term =>
            {
                using (connect.Increment())     // network open
                {
                    return(await WikipediaModel.SearchTermAsync(term, progress));
                }
            })
                            .Switch() // flatten
                            .OnErrorRetry((HttpRequestException ex) => ProgressStatus.Value = "error occured")
                            .ToReactiveProperty();

            // CountChangedStatus : Increment(network open), Decrement(network close), Empty(all complete)
            SearchingStatus = connect
                              .Select(x => (x != CountChangedStatus.Empty) ? "loading..." : "complete")
                              .ToReactiveProperty();

            ProgressStatus = progress
                             .Select(x => string.Format("{0}/{1} {2}%", x.Item1, x.Item2, ((double)x.Item1 / x.Item2) * 100))
                             .ToReactiveProperty();
        }
        public void Test()
        {
            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<int>();

            var notifier = new ScheduledNotifier<int>(testScheduler);
            notifier.Subscribe(recorder);

            notifier.Report(1);
            notifier.Report(2);
            notifier.Report(3, TimeSpan.FromMinutes(10));
            notifier.Report(4, TimeSpan.FromMinutes(1));
            notifier.Report(5, TimeSpan.FromMinutes(5));
            notifier.Report(6);

            testScheduler.Start();

            recorder.Messages.Is(
                OnNext(1, 1),
                OnNext(1, 2),
                OnNext(1, 6),
                OnNext(TimeSpan.FromMinutes(1).Ticks, 4),
                OnNext(TimeSpan.FromMinutes(5).Ticks, 5),
                OnNext(TimeSpan.FromMinutes(10).Ticks, 3));
        }
        public void Test()
        {
            var testScheduler = new TestScheduler();
            var recorder      = testScheduler.CreateObserver <int>();

            var notifier = new ScheduledNotifier <int>(testScheduler);

            notifier.Subscribe(recorder);

            notifier.Report(1);
            notifier.Report(2);
            notifier.Report(3, TimeSpan.FromMinutes(10));
            notifier.Report(4, TimeSpan.FromMinutes(1));
            notifier.Report(5, TimeSpan.FromMinutes(5));
            notifier.Report(6);

            testScheduler.Start();

            recorder.Messages.Is(
                OnNext(1, 1),
                OnNext(1, 2),
                OnNext(1, 6),
                OnNext(TimeSpan.FromMinutes(1).Ticks, 4),
                OnNext(TimeSpan.FromMinutes(5).Ticks, 5),
                OnNext(TimeSpan.FromMinutes(10).Ticks, 3));
        }
        public void TestOffset()
        {
            var testScheduler = new TestScheduler();
            var recorder      = testScheduler.CreateObserver <int>();

            var notifier = new ScheduledNotifier <int>(testScheduler);

            notifier.Subscribe(recorder);

            var origin = new DateTimeOffset(1999, 1, 1, 1, 1, 1, TimeSpan.Zero);

            notifier.Report(1);
            notifier.Report(2);
            notifier.Report(3, origin);
            notifier.Report(4, origin.AddDays(10));
            notifier.Report(5, origin.AddYears(1));
            notifier.Report(6);

            testScheduler.Start();

            recorder.Messages.Is(
                OnNext(1, 1),
                OnNext(1, 2),
                OnNext(1, 6),
                OnNext(origin.Ticks, 3),
                OnNext(origin.AddDays(10).Ticks, 4),
                OnNext(origin.AddYears(1).Ticks, 5));
        }
Ejemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        ObservableWWW.Get("http://WWW.baidu.com").Subscribe(result => {
            Debug.Log(result);
        }, e => {
            Debug.LogError("Error" + e);
        });


        var get1 = ObservableWWW.Get("http://WWW.baidu.com");

        var get2 = ObservableWWW.Get("http://www.sohu.com/");


        Observable.WhenAll(get1, get2).Subscribe(result =>
        {
            Debug.Log(result[0].Substring(0, 100));
            Debug.Log(result[1].Substring(0, 100));
        });

        #region 获取下载进度
        var progressObservable = new ScheduledNotifier <float>();

        ObservableWWW.GetAndGetBytes("http://www.sohu.com/", null, progress: progressObservable).Subscribe(bytes =>
        {
        });

        progressObservable.Subscribe(progress =>
        {
            Debug.LogFormat("进度为 {0}", progress);
        });
        #endregion
    }
Ejemplo n.º 11
0
    public void DownloadFile()
    {
        progress.fillAmount = 0;
        var fileinfo = DownloadPanel.fileinfos[index];

        var pathsave = StandaloneFileBrowser.SaveFilePanel("Open File", Application.persistentDataPath, fileinfo.filename, "");


        var progressNotifier = new ScheduledNotifier <float>();

        progressNotifier.Subscribe(x => progress.fillAmount = x);

        ObservableWWW.GetAndGetBytes(fileinfo.file, null, progressNotifier)
        .Subscribe(
            x =>
        {
            System.IO.File.WriteAllBytes(pathsave, x);
            stateLabel.text = "download success";
        },             // onSuccess
            ex =>
        {
            Debug.Log(ex.ToString());
            stateLabel.text = ex.ToString();
        });             // onError
    }
        public void CancelTest()
        {
            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<int>();

            var notifier = new ScheduledNotifier<int>(testScheduler);
            notifier.Subscribe(recorder);

            var noCancel1 = notifier.Report(10, TimeSpan.FromMinutes(1));
            var cancel1 = notifier.Report(20, TimeSpan.FromMinutes(3));
            cancel1.Dispose();

            recorder.Messages.Count.Is(0);
            testScheduler.AdvanceBy(TimeSpan.FromMinutes(5).Ticks);
            recorder.Messages.Count.Is(1);
            recorder.Messages[0].Is(OnNext(TimeSpan.FromMinutes(1).Ticks, 10));

            var lastTime = recorder.Messages.Last().Time;
            recorder.Messages.Clear();

            var origin = new DateTimeOffset(1999, 1, 1, 1, 1, 1, TimeSpan.Zero);
            var noCancel2 = notifier.Report(30, origin.AddMinutes(1));
            var cancel2 = notifier.Report(40, origin.AddMinutes(3));
            cancel2.Dispose();

            testScheduler.AdvanceTo(origin.AddMinutes(5).Ticks);
            recorder.Messages.Is(
                OnNext(origin.AddMinutes(1).Ticks, 30));
        }
Ejemplo n.º 13
0
    // Start is called before the first frame update
    void Start()
    {
        var clickstream = button.onClick.AsObservable();

        clickstream.Buffer(clickstream.Throttle(TimeSpan.FromMilliseconds(250)))
        .Subscribe(clickcount =>
        {
            if (clickcount.Count == 1)
            {
                var prog = new ScheduledNotifier <float>();
                _wwwObs  = ObservableWWW.GetAndGetBytes("https://speed.hetzner.de/100MB.bin", null, prog)
                           .DoOnTerminate(() => _wwwObs = null)
                           //.DoOnCompleted();
                           .DoOnCancel(() =>
                {
                    Debug.Log("canceled");
                    image.fillAmount = 0;
                });
                prog.Subscribe(x => image.fillAmount = x);

                _canceled = _wwwObs.Subscribe();
            }
            else
            {
                if (_canceled == null)
                {
                    return;
                }
                _canceled.Dispose();
                _canceled = null;
            }
        });
    }
Ejemplo n.º 14
0
    // Use this for initialization
    void Start()
    {
        Resources.LoadAsync <GameObject>("TestCanvas").AsAsyncOperationObservable()
        .Subscribe(resourceRequest =>
        {
            Debug.Log("Resources.LoadAsync()");
            Instantiate(resourceRequest.asset);
        });

        var loadProgress = new ScheduledNotifier <float>();

        Observable.Timer(TimeSpan.FromSeconds(5.0f))
        .Subscribe(_ =>
        {
            SceneManager.LoadSceneAsync("Async").AsAsyncOperationObservable(loadProgress)
            .Subscribe(progress =>
            {
                Debug.Log("load done");
            });

            loadProgress.Subscribe(progress =>
            {
                Debug.LogFormat("Progress:{0}", progress);
            });
        });
    }
Ejemplo n.º 15
0
        private void OnDragAndDrop(Object[] assetObjects)
        {
            if (selectionGroupInfo == null || string.IsNullOrEmpty(selectionGroupInfo.groupName))
            {
                return;
            }

            var assetObject = assetObjects.FirstOrDefault();

            if (assetObject == null)
            {
                return;
            }

            if (!assetManageManager.ValidateManageInfo(assetObject))
            {
                return;
            }

            var assetPath = AssetDatabase.GetAssetPath(assetObject);

            // 管理情報を追加.
            var manageInfo = assetManageManager.AddManageInfo(selectionGroupInfo.groupName, assetObject);

            if (manageInfo != null)
            {
                // 追加された子階層の情報を再収集.

                var progress = new ScheduledNotifier <Tuple <string, float> >();

                progress.Subscribe(
                    x =>
                {
                    EditorUtility.DisplayProgressBar("Collect asset info", x.Item1, x.Item2);
                })
                .AddTo(Disposable);

                assetManageManager.CollectInfo(assetPath, progress);

                EditorUtility.ClearProgressBar();

                // 更新された情報.
                var collectInfos = assetManageManager.GetAllAssetCollectInfo().ToArray();

                // View追加.
                var view = CreateManageInfoView(manageInfo, collectInfos, true, true);

                manageInfoviews = manageInfoviews.Concat(new ManageInfoView[] { view }).ToArray();

                // 管理下に入ったアセットの情報を更新.

                var assetPaths = view.Infos.Select(x => x.AssetPath).ToArray();

                UpdateAssetInfo(assetPaths);

                // View再構築.
                BuildManageInfoViews();
            }
        }
    /// <summary>
    /// 异步加载场景
    /// </summary>
    private void AsAsyncOperationObservable_LoadSceneAsync()
    {
        ScheduledNotifier <float> progress = new ScheduledNotifier <float>();         //预定通知

        SceneManager.LoadSceneAsync("17-异步加载测试").AsAsyncOperationObservable(progress) //异步加载场景 返回异步操作对象
        .Subscribe(_ => print("场景加载完成!"));                                            //当异步操作完成,输出“场景加载完成!”
        progress.Subscribe(_ => print(_));                                            //进度值变更,输出进度值
    }
        public ScheduledNotifierViewModel(ScheduledNotifierModel _model)
        {
            Model = _model.AddTo(DisposeCollection);

            Progress = ScheduledNotifier.ToReadOnlyReactivePropertySlim().AddTo(DisposeCollection);

            TakeLongTimeCommand.Subscribe(TakeLongTimeAsync).AddTo(DisposeCollection);
        }
Ejemplo n.º 18
0
        //----- field -----

        //----- property -----

        //----- method -----

        public static IObservable <BuiltInAssetInfo[]> CollectBuiltInAssets(string logFilePath)
        {
            var progress = new ScheduledNotifier <float>();

            progress.Subscribe(prog => EditorUtility.DisplayProgressBar("progress", "Collect built-in assets from logfile.", prog));

            return(Observable.FromCoroutine <BuiltInAssetInfo[]>(observer => CollectBuiltInAssetsInternal(observer, logFilePath, progress))
                   .Do(x => EditorUtility.ClearProgressBar()));
        }
Ejemplo n.º 19
0
    /// <summary>
    /// 初始化函数
    /// </summary>
    void Start()
    {
        var slider           = GameObject.Find("Slider").GetComponent <Slider>();     //滑动器
        var progressText     = GameObject.Find("ProgressText").GetComponent <Text>(); //进度条文本
        var progressNotifier = new ScheduledNotifier <float>();                       //RX 预定通知 float

        //尚未拥有服务器的,可以看我的教程购买;也可,直接使用以下地址资源进行测试,Chinar会为大家永久预留!
        ObservableWWW.GetAndGetBytes("http://www.chinar.xin/chinarweb/Assets/Test/UniRx/ChinarTestAssets.rar", progress: progressNotifier).Subscribe(bytes => { }); //下载完成,做储存
        progressNotifier.Subscribe(progressFloat => { slider.value = progressFloat; });                                                                             //更新进度
        progressNotifier.SubscribeToText(progressText);                                                                                                             //进度值显示在 progressText
    }
Ejemplo n.º 20
0
        public void ProgressDownload()
        {
            // with Progress
            // notifier for progress
            var progressNotifier = new ScheduledNotifier <float>();

            progressNotifier.Subscribe(x => Debug.Log(x)); // write www.progress

            // pass notifier to WWW.Get/Post
            ObservableWWW.Get("http://google.com/", progress: progressNotifier).Subscribe();
        }
Ejemplo n.º 21
0
        void Start()
        {
            var progressObservable = new ScheduledNotifier <float>();

            ObservableWWW.GetAndGetBytes("http://liangxiegame.com/media/QFramework_v0.0.9.unitypackage", progress: progressObservable) //ダウンロードの進捗状況
            .Subscribe(byts =>
            {
            });
            progressObservable.Subscribe(progress =>
            {
                Debug.LogFormat("完成:{0}%", progress * 100);   //進捗状況監視
            });
        }
Ejemplo n.º 22
0
    // Use this for initialization
    void Start()
    {
        var progressObservable = new ScheduledNotifier <float>();

        ObservableWWW.GetAndGetBytes("http://liangxiegame.com/media/QFramework_v0.0.9.unitypackage", progress: progressObservable)
        .Subscribe(bytes =>
        {
        });

        progressObservable.Subscribe(progress =>
        {
            Debug.LogFormat("进度为:{0}", progress);
        });
    }
Ejemplo n.º 23
0
    public void Upload()
    {
        if (string.IsNullOrEmpty(pathInput.text) || !System.IO.File.Exists(pathInput.text))
        {
            errorLabel.text = "Please Select File!!!";
            errorLabel.gameObject.SetActive(true);
            return;
        }
        else

        {
            errorLabel.text = "Uploading";
            errorLabel.gameObject.SetActive(true);

            manager.Lock = true;

            WWWForm form = new WWWForm();

            var file = File.ReadAllBytes(pathInput.text);
            form.AddBinaryData("file", file);
            var fileinfo = (new System.IO.FileInfo(pathInput.text));
            form.AddField("filename", fileinfo.Name);

            string authorization = authenticate(Registry.username, Registry.password);
            Dictionary <string, string> headers = new Dictionary <string, string>();
            headers.Add("AUTHORIZATION", authorization);

            var progressNotifier = new ScheduledNotifier <float>();
            progressNotifier.Subscribe(x => progress.fillAmount = x);

            ObservableWWW.Post(Constants.API_FILE, form, headers, progressNotifier)
            .Subscribe(
                x =>
            {
                Debug.Log("Upload success");
                errorLabel.text = "upload success";
                errorLabel.gameObject.SetActive(true);

                manager.Lock = false;
            },          // onSuccess
                ex =>
            {
                Debug.Log(ex.ToString());
                errorLabel.text = ex.ToString();
                errorLabel.gameObject.SetActive(true);
                manager.Lock = false;
            });          // onError
        }
    }
Ejemplo n.º 24
0
        public static void SetCriAssetFileInfo(string exportPath, string externalResourcesPath, AssetBundleManifest assetBundleManifest)
        {
            var manifestPath      = GetManifestPath(externalResourcesPath);
            var assetInfoManifest = AssetDatabase.LoadAssetAtPath <AssetInfoManifest>(manifestPath);

            var progress = new ScheduledNotifier <Tuple <string, float> >();

            progress.Subscribe(prog => EditorUtility.DisplayProgressBar("Update cri file info", prog.Item1, prog.Item2));

            assetInfoManifest.SetCriAssetFileInfo(exportPath, progress);

            UnityEditorUtility.SaveAsset(assetInfoManifest);

            EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 25
0
    // Start is called before the first frame update
    void Start()
    {
        //Resources.LoadAsync<GameObject>("TestCanvas").AsAsyncOperationObservable().Subscribe(request =>
        //{
        //    Instantiate(request.asset);
        //});

        ScheduledNotifier <float> progressObservable = new ScheduledNotifier <float>();

        SceneManager.LoadSceneAsync(0).AsAsyncOperationObservable(progressObservable).Subscribe(_ =>
        {
            Debug.Log("Load done.");
        });

        progressObservable.Subscribe(progress => Debug.LogFormat("╪стьакё╨{0}%", progress * 100));
    }
Ejemplo n.º 26
0
    protected override void OnUpdate()
    {
        base.OnUpdate();

        if (Input.GetKeyDown(KeyCode.D))
        { // with Progress
            {
                // notifier for progress
                var progressNotifier = new ScheduledNotifier <float>();
                progressNotifier.Subscribe(x => _Progress.fillAmount = x); // write www.progress

                // pass notifier to WWW.Get/Post
                ObservableWWW.Get("http://google.com/", progress: progressNotifier).Subscribe();
            }
        }
    }
Ejemplo n.º 27
0
        private void LoadSceneRx()
        {
            var progressObservable = new ScheduledNotifier <float>();

            progressObservable.Subscribe(progress => { Debug.LogFormat("Loading: {0}", progress); });

            // Load Default Scene 0
            SceneManager.LoadSceneAsync(0).AsAsyncOperationObservable(progressObservable)
            .Subscribe(asyncOperation =>
            {
                var player = new GameObject {
                    name = "[NewObject] Jack"
                };
                Debug.Log($"Done! Hi, {player.name}.");
            });
        }
Ejemplo n.º 28
0
        public void CollectInfo()
        {
            var progress = new ScheduledNotifier <Tuple <string, float> >();

            progress.Subscribe(
                x =>
            {
                EditorUtility.DisplayProgressBar("Collect asset info", x.Item1, x.Item2);
            })
            .AddTo(Disposable);

            assetCollectInfoByAssetPath.Clear();

            CollectInfo(externalResourcesPath, progress);

            EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 29
0
    // Start is called before the first frame update
    void Start()
    {
        ObservableWWW.Get("http://www.sikiedu.com")
        .Subscribe(responseTxt =>
        {
            Debug.Log(responseTxt);
        }, e =>
        {
            Debug.Log(e);
        });


        ObservableWWW.Get("http://www.iqiyi.com")
        .Subscribe(responseText =>
        {
            Debug.Log(responseText);
        }, e =>
        {
            Debug.Log(e);
        });

        var wwwA = ObservableWWW.Get("http://www.baidu.com");
        var wwwB = ObservableWWW.Get("http://www.iqiyi.com");

        Observable.WhenAll(wwwA, wwwB)
        .Subscribe(responseText =>
        {
            Debug.LogFormat("{0}{1}", responseText[0].Substring(0, 10), responseText[1].Substring(0, 10));
        })
        .AddTo(this);


        var progressObervable = new ScheduledNotifier <float>();

        ObservableWWW.GetAndGetBytes("https://github.com/liangxiegame/QFramework/releases/tag/v0.0.9", null, progressObervable)
        .Subscribe(bytes =>
        {
            File.WriteAllBytes(Application.dataPath + "/ss.unitypackage", bytes);
        });

        progressObervable.Subscribe(progress =>
        {
            Debug.LogFormat("进度为:{0}", progress);
        });
    }
        void Start()
        {
            var progressObservable = new ScheduledNotifier <float>();

            ObservableWWW
            .GetAndGetBytes("http://po8veecle.bkt.clouddn.com/UniRx_MVP.jpg",
                            null,
                            progressObservable)
            .Subscribe(bytes =>
            {
                Debug.Log("文件大小为:" + (bytes.Length / 1000) + "k");
            });

            progressObservable.Subscribe(progress =>
            {
                Debug.LogFormat("j进度为:{0}", progress);
            });
        }
Ejemplo n.º 31
0
    private void GetRequestObservable()
    {
        var progress = new ScheduledNotifier <float>();

        progress.Subscribe(prog => Debug.Log(prog))
        .AddTo(this);

        ObservableWWW.Get(url + query, progress: progress)
        .Subscribe(
            x =>
        {
            Debug.Log($"get success. {nameof(WWWSamples)}.{nameof(GetRequestObservable)}");
            Debug.Log(x);
        },
            ex => Debug.Log(ex.Message),
            () => Debug.Log("completed."))
        .AddTo(this);
    }
Ejemplo n.º 32
0
        private IEnumerator PostReport()
        {
            yield return(CaptureScreenshot());

            yield return(new WaitForEndOfFrame());

            UpdateView();

            // 進捗.
            var notifier = new ScheduledNotifier <float>();

            notifier.Subscribe(x => UpdatePostProgress(x));

            reportForm.Clear();

            // 送信内容構築.
            BuildPostContent();

            // 送信.
            var webRequest = UnityWebRequest.Post(PostReportURL, reportForm);

            webRequest.timeout = 30;

            var operation = webRequest.SendWebRequest();

            while (!operation.isDone)
            {
                notifier.Report(operation.progress);

                yield return(null);
            }

            var errorMessage = string.Empty;

            if (webRequest.isNetworkError || webRequest.isHttpError)
            {
                errorMessage = string.Format("[{0}]{1}", webRequest.responseCode, webRequest.error);
            }

            // 終了.
            OnReportComplete(errorMessage);

            reportForm.Clear();
        }
Ejemplo n.º 33
0
Archivo: Test.cs Proyecto: BetrC/UniRx
        /** 案例不正确,慎用,关于异步有待进一步学习*/
        public static void AsyncExample()
        {
            var progressObservable = new ScheduledNotifier <float>();

            SceneManager.LoadSceneAsync(0).AsAsyncOperationObservable(progressObservable)
            .Subscribe(asyncOperation =>
            {
                Debug.Log("load done");

                Resources.LoadAsync <GameObject>("TestCanvas").AsAsyncOperationObservable()
                .Subscribe(_ =>
                {
                    Debug.Log("Hello");
                    // Object.Instantiate(resourceRequest.asset);
                });
            });

            progressObservable.Subscribe(progress => { Debug.LogFormat("加载了:{0}", progress); });
        }
Ejemplo n.º 34
0
    private void PostRequestObservable()
    {
        var form = new WWWForm();

        form.AddField(key, zipcode);

        var progress = new ScheduledNotifier <float>();

        progress.Subscribe(prog => Debug.Log(prog))
        .AddTo(this);

        ObservableWWW.Post(url, form, progress)
        .Subscribe(x =>
        {
            Debug.Log($"post success. {nameof(WWWSamples)}.{nameof(PostRequestObservable)}");
            Debug.Log(x);
        })
        .AddTo(this);
    }
        void Start()
        {
            // Basic: Download from google.
            {
                ObservableWWW.Get("http://google.co.jp/")
                    .Subscribe(
                        x => Debug.Log(x.Substring(0, 100)), // onSuccess
                        ex => Debug.LogException(ex)); // onError
            }

            // Linear Pattern with LINQ Query Expressions
            // download after google, start bing download
            {
                var query = from google in ObservableWWW.Get("http://google.com/")
                            from bing in ObservableWWW.Get("http://bing.com/")
                            select new { google, bing };

                var cancel = query.Subscribe(x => Debug.Log(x.google.Substring(0, 100) + ":" + x.bing.Substring(0, 100)));

                // Call Dispose is cancel downloading.
                cancel.Dispose();
            }

            // Observable.WhenAll is for parallel asynchronous operation
            // (It's like Observable.Zip but specialized for single async operations like Task.WhenAll of .NET 4)
            {
                var parallel = Observable.WhenAll(
                    ObservableWWW.Get("http://google.com/"),
                    ObservableWWW.Get("http://bing.com/"),
                    ObservableWWW.Get("http://unity3d.com/"));

                parallel.Subscribe(xs =>
                {
                    Debug.Log(xs[0].Substring(0, 100)); // google
                    Debug.Log(xs[1].Substring(0, 100)); // bing
                    Debug.Log(xs[2].Substring(0, 100)); // unity
                });
            }

            // with Progress
            {
                // notifier for progress
                var progressNotifier = new ScheduledNotifier<float>();
                progressNotifier.Subscribe(x => Debug.Log(x)); // write www.progress

                // pass notifier to WWW.Get/Post
                ObservableWWW.Get("http://google.com/", progress: progressNotifier).Subscribe();
            }

            // with Error
            {
                // If WWW has .error, ObservableWWW throws WWWErrorException to onError pipeline.
                // WWWErrorException has RawErrorMessage, HasResponse, StatusCode, ResponseHeaders
                ObservableWWW.Get("http://www.google.com/404")
                    .CatchIgnore((WWWErrorException ex) =>
                    {
                        Debug.Log(ex.RawErrorMessage);
                        if (ex.HasResponse)
                        {
                            Debug.Log(ex.StatusCode);
                        }
                        foreach (var item in ex.ResponseHeaders)
                        {
                            Debug.Log(item.Key + ":" + item.Value);
                        }
                    })
                    .Subscribe();
            }
        }