Exemplo n.º 1
0
        private Texture2D GetTexture(string file)
        {
            byte[] bytes = DiskStorage.Read(file);

            return(GetTexture(bytes));
        }
Exemplo n.º 2
0
        public void DownloadOrLoadTexture(string url, string fileName, Action <Texture2D> callback)
        {
            if (InCache(fileName))
            {
                if (callback != null)
                {
                    callback(_cache[fileName]);
                }

                return;
            }

            if (InDisk(fileName))
            {
                var texture = GetTexture(fileName);

                _cache.Add(fileName, texture);

                if (callback != null)
                {
                    callback(_cache[fileName]);
                }

                return;
            }

            if (_downloadingQueu.ContainsKey(fileName))
            {
                _downloadingQueu[fileName].Add(callback);
                return;
            }

            _downloadingQueu.Add(fileName, new List <Action <Texture2D> >());
            _downloadingQueu[fileName].Add(callback);

            _coroutineExecuter.Execute(LoadTexture(url, data =>
            {
                //error loading
                if (data == null)
                {
                    LogError("Can'not load image data:" + fileName);

                    ExecuteCallback(fileName, null);

                    return;
                }

                var texture = GetTexture(data);

                if (texture == null)
                {
                    LogError("Can'not parse image data:" + fileName);

                    ExecuteCallback(fileName, null);

                    return;
                }

                if (_cache.ContainsKey(fileName))
                {
                    _cache[fileName] = texture;
                }
                else
                {
                    _cache.Add(fileName, texture);
                }

                try
                {
                    DiskStorage.Write(fileName, data);
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }

                ExecuteCallback(fileName, texture);
            }));
        }
Exemplo n.º 3
0
 public bool InDisk(string file)
 {
     return(DiskStorage.Exists(file));
 }