Beispiel #1
0
    void Start()
    {
        // sprite file cache domain. can be path.
        var spriteDomain = "persistence/sprite_cache";

        // purge all files in domain.
        Autoya.Persist_URLCaching_PurgeByDomain(spriteDomain);

        // download image from url, then get cached & sprite assets asynchronously.
        var queryString = "?q=0";

        Autoya.Persist_URLCaching_Load <Sprite>(
            spriteDomain,
            "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Jewelkatz_Romeo_Of_Stalker-Bars.jpg/500px-Jewelkatz_Romeo_Of_Stalker-Bars.jpg" + queryString,
            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 =>
        {
            // attach cached sprite to current screen image.
            image.sprite = cached;

            // set aspect.
            image.preserveAspect = true;
        },
            (code, reason) =>
        {
            Debug.LogError("code:" + code + " reason:" + reason);
        }
            );
    }
Beispiel #2
0
 public void Teardown()
 {
     // delete all cache.
     Autoya.Persist_URLCaching_PurgeByDomain(AutoyaURLCachingTestsFileDomain);
 }
Beispiel #3
0
    public IEnumerator PurgeByDomainThenGetNew()
    {
        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 =>
        {
            sprite = cached;
            loaded = true;
        },
            (code, reason) =>
        {
            Fail("reason:" + reason);
        }
            );

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

        Autoya.Persist_URLCaching_PurgeByDomain(AutoyaURLCachingTestsFileDomain);

        var loadedAgain = false;

        // call 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(sprite != cached, "nothing changed.");
            loadedAgain = true;
        },
            (code, reason) =>
        {
            Fail("reason:" + reason);
        }
            );

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