Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        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); // Already downloaded
                }
            }

            TaskFinished("SwrveAssetsManager.DownloadAssetQueue");
        }
Ejemplo n.º 3
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);
                }
            }
        }