Пример #1
0
    private IEnumerator AsyncLoadImage(string filePath, TextureFormat textureFormat)
    {
        this.rawImage.texture = this.defaultTexture;
        this.uiController.SetButtonInteractable(false);

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        for (int i = 0; i < TRIAL_COUNT; i++)
        {
            AsyncTextureReader.Read(
                new AsyncTextureReader.TextureData {
                filePath = filePath,
                format   = textureFormat,
                width    = 1000,
                height   = 1000
            },
                texture => {
                this.rawImage.texture = texture;
                this.rawImage.SetNativeSize();
                this.uiController.SetProgressText(
                    AsyncTextureReader.Progress.totalCount,
                    AsyncTextureReader.Progress.processedCount
                    );
            }
                );
        }

        WaitUntil waitUntil = new WaitUntil(() => !AsyncTextureReader.Progress.IsRuntime);

        yield return(waitUntil);

        sw.Stop();
        this.uiController.SetProcessedTime(sw.Elapsed.ToString());

        this.uiController.SetButtonInteractable(true);
        Resources.UnloadUnusedAssets();
        GC.Collect();
    }