Example #1
0
        IPromise <Codec> _loadAsync(FileImage key)
        {
            var coroutine = Window.instance.startCoroutine(this._loadBytes(key));

            return(coroutine.promise.Then(obj => {
                if (obj is byte[] bytes)
                {
                    return CodecUtils.getCodec(bytes);
                }

                return CodecUtils.getCodec(new Image((Texture2D)obj));
            }));
        }
Example #2
0
        IPromise <Codec> _loadAsync(AssetBundleImageKey key)
        {
            var coroutine = Window.instance.startCoroutine(this._loadAssetAsync(key));

            return(coroutine.promise.Then(result => {
                if (result == null)
                {
                    if (key.bundle == null)
                    {
                        throw new Exception($"Unable to find asset \"{key.name}\" from Resources folder");
                    }

                    throw new Exception($"Unable to find asset \"{key.name}\" from asset bundle \"{key.bundle}\"");
                }

                if (result is Texture2D texture)
                {
                    return CodecUtils.getCodec(new Image(texture, isAsset: true, bundle: key.bundle));
                }
                else if (result is TextAsset text)
                {
                    var bytes = text.bytes;
                    if (key.bundle == null)
                    {
                        Resources.UnloadAsset(text);
                    }
                    else
                    {
                        key.bundle.Unload(text);
                    }

                    return CodecUtils.getCodec(bytes);
                }
                else
                {
                    throw new Exception($"Unknown type for asset \"{key.name}\": \"{result.GetType()}\"");
                }
            }));
        }
        IPromise <Codec> _loadAsync(CachedNetworkImageProvider key)
        {
            var localPath = SQLiteDBManager.instance.GetCachedFilePath(url: key.url);

            //the cached file might be deleted by the OS
            if (!File.Exists(path: localPath))
            {
                localPath = null;
            }

            var coroutine = localPath != null
                ? Window.instance.startCoroutine(this._loadFromFile(file : localPath))
                            : Window.instance.startCoroutine(this._loadFromNetwork(url : key.url));

            return(coroutine.promise.Then(obj => {
                if (obj is byte[] bytes)
                {
                    return CodecUtils.getCodec(bytes: bytes);
                }

                return CodecUtils.getCodec(new Image((Texture2D)obj));
            }));
        }
Example #4
0
        IPromise <Codec> _loadAsync(MemoryImage key)
        {
            D.assert(key == this);

            return(CodecUtils.getCodec(this.bytes));
        }