Exemple #1
0
    public IEnumerator PurgeThenGetNew()
    {
        Sprite sprite = null;


        var loaded    = false;
        var imagePath = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9e/2016-06-14_Orange_and_white_tabby_cat_born_in_2016_茶トラ白ねこ_DSCF6526☆彡.jpg/400px-2016-06-14_Orange_and_white_tabby_cat_born_in_2016_茶トラ白ねこ_DSCF6526☆彡.jpg?a=b";

        Autoya.Persist_URLCaching_Load(
            AutoyaURLCachingTestsFileDomain,
            imagePath,
            bytes =>
        {
            // return sprite from bytes.
            var tex = new Texture2D(1, 1);
            tex.LoadImage(bytes);
            var newSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(.5f, .5f));
            return(newSprite);
        },
            cached =>
        {
            True(cached != null, "cached is null.");
            sprite = cached;
            loaded = true;
        },
            (code, reason) =>
        {
            Fail();
        }
            );

        yield return(WaitUntil(
                         () => loaded,
                         () => { throw new TimeoutException("timeout."); }
                         ));

        // purge cache.
        Autoya.Persist_URLCaching_Purge(AutoyaURLCachingTestsFileDomain, imagePath);

        var loadedAgain = false;

        // get again.
        Autoya.Persist_URLCaching_Load(
            AutoyaURLCachingTestsFileDomain,
            imagePath,
            bytes =>
        {
            // return sprite from bytes.
            var tex = new Texture2D(1, 1);
            tex.LoadImage(bytes);
            var newSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(.5f, .5f));
            return(newSprite);
        },
            cached =>
        {
            True(cached != null, "cached is null.");
            True(sprite.GetInstanceID() != cached.GetInstanceID(), "nothing changed. sprite:" + sprite + " cached:" + cached);
            loadedAgain = true;
        },
            (code, reason) =>
        {
            Fail();
        }
            );

        yield return(WaitUntil(
                         () => loadedAgain,
                         () => { throw new TimeoutException("timeout."); }
                         ));
    }