Esempio n. 1
0
        protected virtual IEnumerator DownloadAsset(SwrveAssetsQueueItem item)
        {
            string cdn = item.IsImage ? CdnImages : CdnFonts;
            string url = cdn + item.Name;

            SwrveLog.Log("Downloading asset: " + url);
            UnityWebRequest www = (item.IsImage)? UnityWebRequestTexture.GetTexture(url) : new UnityWebRequest(url);

            if (!item.IsImage)
            {
                DownloadHandlerBuffer dH = new DownloadHandlerBuffer();
                www.downloadHandler = dH;
            }
            yield return(www.SendWebRequest());

            if (!www.isNetworkError && !www.isHttpError)
            {
                if (item.IsImage)
                {
                    SaveImageAsset(item, www);
                }
                else
                {
                    SaveBinaryAsset(item, www);
                }
            }
            else
            {
                MissingAssetsQueue.Add(item);
            }
            TaskFinished("SwrveAssetsManager.DownloadAsset");
        }
Esempio n. 2
0
        protected virtual IEnumerator DownloadAsset(SwrveAssetsQueueItem item)
        {
            string str  = (!item.IsImage) ? this.CdnFonts : this.CdnImages;
            string text = str + item.Name;

            SwrveLog.Log("Downloading asset: " + text);
            WWW wWW = new WWW(text);

            yield return(wWW);

            WwwDeducedError wwwDeducedError = UnityWwwHelper.DeduceWwwError(wWW);

            if (wWW != null && wwwDeducedError == WwwDeducedError.NoError && wWW.isDone)
            {
                if (item.IsImage)
                {
                    this.SaveImageAsset(item, wWW);
                }
                else
                {
                    this.SaveBinaryAsset(item, wWW);
                }
            }
            this.TaskFinished("SwrveAssetsManager.DownloadAsset");
            yield break;
        }
        protected virtual IEnumerator DownloadAsset(SwrveAssetsQueueItem item)
        {
            string cdn = (item.IsImage ? CdnImages : CdnFonts);
            string url = cdn + item.Name;

            SwrveLog.Log("Downloading asset: " + url);
            WWW www = new WWW(url);

            yield return(www);

            WwwDeducedError err = UnityWwwHelper.DeduceWwwError(www);

            if (www != null && err == WwwDeducedError.NoError && www.isDone)
            {
                if (item.IsImage)
                {
                    SaveImageAsset(item, www);
                }
                else
                {
                    SaveBinaryAsset(item, www);
                }
            }
            TaskFinished("SwrveAssetsManager.DownloadAsset");
        }
Esempio n. 4
0
        protected virtual void SaveBinaryAsset(SwrveAssetsQueueItem item, WWW www)
        {
            byte[] bytes = www.bytes;
            string text  = SwrveHelper.sha1(bytes);

            if (text == item.Digest)
            {
                string temporaryPathFileName = this.GetTemporaryPathFileName(item.Name);
                SwrveLog.Log("Saving to " + temporaryPathFileName);
                CrossPlatformFile.SaveBytes(temporaryPathFileName, bytes);
                this.AssetsOnDisk.Add(item.Name);
            }
            else
            {
                SwrveLog.Log("Error downloading binary assetItem:" + item.Name + ". Did not match digest:" + text);
            }
        }
Esempio n. 5
0
        protected virtual void SaveBinaryAsset(SwrveAssetsQueueItem item, UnityWebRequest www)
        {
            byte[] bytes = www.downloadHandler.data;
            string sha1  = SwrveHelper.sha1(bytes);

            if (sha1 == item.Digest)
            {
                string filePath = GetTemporaryPathFileName(item.Name);
                SwrveLog.Log("Saving to " + filePath);
                CrossPlatformFile.SaveBytes(filePath, bytes);
                bytes = null;
                AssetsOnDisk.Add(item.Name);
            }
            else
            {
                SwrveLog.Log("Error downloading binary assetItem:" + item.Name + ". Did not match digest:" + sha1);
            }
        }
        private IEnumerator DownloadAssetQueue(HashSet <SwrveAssetsQueueItem> assetsQueue)
        {
            IEnumerator <SwrveAssetsQueueItem> enumerator = assetsQueue.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SwrveAssetsQueueItem item = enumerator.Current;
                if (!CheckAsset(item.Name))
                {
                    yield return(StartTask("SwrveAssetsManager.DownloadAsset", DownloadAsset(item)));
                }
                else
                {
                    AssetsOnDisk.Add(item.Name);
                }
            }
            TaskFinished("SwrveAssetsManager.DownloadAssetQueue");
        }
Esempio n. 7
0
        private IEnumerator DownloadAssetQueue(HashSet <SwrveAssetsQueueItem> assetsQueue)
        {
            IEnumerator <SwrveAssetsQueueItem> enumerator = assetsQueue.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SwrveAssetsQueueItem current = enumerator.Current;
                if (!this.CheckAsset(current.Name))
                {
                    yield return(this.StartTask("SwrveAssetsManager.DownloadAsset", this.DownloadAsset(current)));
                }
                else
                {
                    this.AssetsOnDisk.Add(current.Name);
                }
            }
            this.TaskFinished("SwrveAssetsManager.DownloadAssetQueue");
            yield break;
        }
Esempio n. 8
0
        protected virtual void SaveImageAsset(SwrveAssetsQueueItem item, WWW www)
        {
            Texture2D texture = www.texture;

            if (texture != null)
            {
                byte[] bytes = www.bytes;
                string text  = SwrveHelper.sha1(bytes);
                if (text == item.Digest)
                {
                    byte[] bytes2 = texture.EncodeToPNG();
                    string temporaryPathFileName = this.GetTemporaryPathFileName(item.Name);
                    SwrveLog.Log("Saving to " + temporaryPathFileName);
                    CrossPlatformFile.SaveBytes(temporaryPathFileName, bytes2);
                    UnityEngine.Object.Destroy(texture);
                    this.AssetsOnDisk.Add(item.Name);
                }
                else
                {
                    SwrveLog.Log("Error downloading image assetItem:" + item.Name + ". Did not match digest:" + text);
                }
            }
        }
Esempio n. 9
0
        protected virtual void SaveImageAsset(SwrveAssetsQueueItem item, UnityWebRequest www)
        {
            Texture2D loadedTexture = ((DownloadHandlerTexture)www.downloadHandler).texture;

            if (loadedTexture != null)
            {
                byte[] rawBytes = www.downloadHandler.data;
                string sha1     = SwrveHelper.sha1(rawBytes);
                if (sha1 == item.Digest)
                {
                    byte[] bytes    = loadedTexture.EncodeToPNG();
                    string filePath = GetTemporaryPathFileName(item.Name);
                    SwrveLog.Log("Saving to " + filePath);
                    CrossPlatformFile.SaveBytes(filePath, bytes);
                    bytes = null;
                    Texture2D.Destroy(loadedTexture);
                    AssetsOnDisk.Add(item.Name);
                }
                else
                {
                    SwrveLog.Log("Error downloading image assetItem:" + item.Name + ". Did not match digest:" + sha1);
                }
            }
        }
Esempio n. 10
0
        public override bool Equals(object obj)
        {
            SwrveAssetsQueueItem swrveAssetsQueueItem = obj as SwrveAssetsQueueItem;

            return(swrveAssetsQueueItem != null && swrveAssetsQueueItem.Name == this.Name && swrveAssetsQueueItem.Digest == this.Digest && swrveAssetsQueueItem.IsImage == this.IsImage);
        }