Esempio n. 1
0
 public LargeFilePending(string url, string filepath, Dictionary <string, string> extraParams, AssetStoreClient.DoneCallback doneCallback, AssetStoreClient.ProgressCallback progressCallback)
 {
     this.Id                      = filepath;
     this.URI                     = url;
     this.FilePath                = filepath;
     this.RequestDoneCallback     = doneCallback;
     this.RequestProgressCallback = progressCallback;
     this.m_extraParams           = extraParams;
 }
    public static ImageCache DownloadImage(Image img, ImageCache.DownloadCallback callback)
    {
        ImageCache imageCache;

        if (img == null || img.mUrl == null)
        {
            return(null);
        }

        if (!ImageCache.EntriesByUrl.TryGetValue(img.mUrl, out imageCache))
        {
            ImageCache.EnsureCacheSpace();
            imageCache = new ImageCache()
            {
                Failed         = false,
                Texture        = null,
                m_DownloadedAt = -1,
                LastUsed       = EditorApplication.timeSinceStartup
            };
            ImageCache.EntriesByUrl[img.mUrl] = imageCache;
        }
        else if (imageCache.Texture != null || imageCache.Progress >= 0f || imageCache.Failed)
        {
            img.mImgCache = imageCache;
            return(imageCache);
        }

        img.mImgCache       = imageCache;
        imageCache.Progress = 0f;
        AssetStoreClient.ProgressCallback progress     = (double pctUp, double pctDown) => imageCache.Progress = (float)pctDown;
        AssetStoreClient.DoneCallback     doneCallback = (AssetStoreResponse resp) =>
        {
            imageCache.Progress       = -1f;
            imageCache.LastUsed       = EditorApplication.timeSinceStartup;
            imageCache.m_DownloadedAt = imageCache.LastUsed;
            imageCache.Failed         = resp.failed;
            if (resp.ok && resp.binData != null && (int)resp.binData.Length > 0)
            {
                Texture2D texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                texture2D.LoadImage(resp.binData);
                imageCache.Texture = texture2D;
            }

            if (callback != null)
            {
                string str = string.Format("Error fetching {0}", img.Name);
                if (resp.failed)
                {
                    DebugUtils.LogWarning(string.Concat(str, string.Format(" : ({0}) {1} from {2}", resp.HttpStatusCode, resp.HttpErrorMessage ?? "n/a", img.mUrl)));
                }

                callback(img, imageCache, (!resp.ok ? str : null));
            }
        };
        AssetStoreClient.LoadFromUrl(img.mUrl, doneCallback, progress);
        return(imageCache);
    }
Esempio n. 3
0
    public static ImageCache DownloadImage(Image img, ImageCache.DownloadCallback callback)
    {
        if (img == null || img.mUrl == null)
        {
            return(null);
        }
        ImageCache ic;

        if (ImageCache.EntriesByUrl.TryGetValue(img.mUrl, out ic))
        {
            if (ic.Texture != null || ic.Progress >= 0f || ic.Failed)
            {
                img.mImgCache = ic;
                return(ic);
            }
        }
        else
        {
            ImageCache.EnsureCacheSpace();
            ic                = new ImageCache();
            ic.Failed         = false;
            ic.Texture        = null;
            ic.m_DownloadedAt = -1.0;
            ic.LastUsed       = EditorApplication.timeSinceStartup;
            ImageCache.EntriesByUrl[img.mUrl] = ic;
        }
        img.mImgCache = ic;
        ic.Progress   = 0f;
        AssetStoreClient.ProgressCallback progress = delegate(double pctUp, double pctDown)
        {
            ic.Progress = (float)pctDown;
        };
        AssetStoreClient.DoneCallback callback2 = delegate(AssetStoreResponse resp)
        {
            ic.Progress       = -1f;
            ic.LastUsed       = EditorApplication.timeSinceStartup;
            ic.m_DownloadedAt = ic.LastUsed;
            ic.Failed         = resp.failed;
            if (resp.ok && resp.binData != null && resp.binData.Length > 0)
            {
                Texture2D texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false);
                texture2D.LoadImage(resp.binData);
                ic.Texture = texture2D;
            }
            if (callback != null)
            {
                string text = string.Format("Error fetching {0}", img.Name);
                if (resp.failed)
                {
                    DebugUtils.LogWarning(text + string.Format(" : ({0}) {1} from {2}", resp.HttpStatusCode, resp.HttpErrorMessage ?? "n/a", img.mUrl));
                }
                callback(img, ic, (!resp.ok) ? text : null);
            }
        };
        AssetStoreClient.LoadFromUrl(img.mUrl, callback2, progress);
        return(ic);
    }
 public static void UploadLargeFile(string path, string filepath, Dictionary <string, string> extraParams, AssetStoreClient.DoneCallback callback, AssetStoreClient.ProgressCallback progressCallback)
 {
     AssetStoreClient.LargeFilePending item = new AssetStoreClient.LargeFilePending(path, filepath, extraParams, callback, progressCallback);
     AssetStoreClient.s_PendingLargeFiles.Add(item);
 }
 public static void LoadFromUrl(string url, AssetStoreClient.DoneCallback callback, AssetStoreClient.ProgressCallback progress)
 {
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePendingGetBinary(url, url, callback);
     pending.progressCallback = progress;
 }
Esempio n. 6
0
    public static void UploadAssets(Package package, string newGUID, string newRootPath, string newProjectpath, string filepath, AssetStoreAPI.DoneCallback callback, AssetStoreClient.ProgressCallback progress)
    {
        string path = string.Format("/package/{0}/unitypackage", package.versionId);

        AssetStoreClient.UploadLargeFile(path, filepath, new Dictionary <string, string>
        {
            {
                "root_guid",
                newGUID
            },
            {
                "root_path",
                newRootPath
            },
            {
                "project_path",
                newProjectpath
            }
        }, delegate(AssetStoreResponse resp)
        {
            if (resp.HttpStatusCode == -2)
            {
                callback("aborted");
                return;
            }
            string errorMessage = null;
            JSONValue jSONValue;
            AssetStoreAPI.Parse(resp, out errorMessage, out jSONValue);
            callback(errorMessage);
        }, progress);
    }
Esempio n. 7
0
 public static void UploadBundle(string path, string filepath, AssetStoreAPI.UploadBundleCallback callback, AssetStoreClient.ProgressCallback progress)
 {
     AssetStoreClient.UploadLargeFile(path, filepath, null, delegate(AssetStoreResponse resp)
     {
         string errorMessage = null;
         JSONValue jSONValue;
         AssetStoreAPI.Parse(resp, out errorMessage, out jSONValue);
         callback(filepath, errorMessage);
     }, progress);
 }
Esempio n. 8
0
 private static void Upload(string path, string filepath, AssetStoreAPI.DoneCallback callback, AssetStoreClient.ProgressCallback progress = null)
 {
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePendingUpload(path, path, filepath, delegate(AssetStoreResponse resp)
     {
         string errorMessage = null;
         JSONValue jSONValue;
         AssetStoreAPI.Parse(resp, out errorMessage, out jSONValue);
         callback(errorMessage);
     });
     pending.progressCallback = progress;
 }
Esempio n. 9
0
    public static void UploadAssets(Package package, string localRootGuid, string localRootPath, string projectPath, string draftAssetsPath, DoneCallback callback, AssetStoreClient.ProgressCallback progressCallback)
    {
        Type doneCallbackType, clientProgressCallbackType;
        var  doneCallback           = CreateCallbackDelegate("DoneCallback", callback, out doneCallbackType);
        var  clientProgressCallback = AssetStoreClient.CreateCallbackDelegate("ProgressCallback", progressCallback, out clientProgressCallbackType);

        s_Instance.GetRuntimeType().Invoke("UploadAssets", package.GetRuntimeObject().Param(), localRootGuid.Param(), localRootPath.Param(), projectPath.Param(), draftAssetsPath.Param(), new Parameter(doneCallback, doneCallbackType), new Parameter(clientProgressCallback, clientProgressCallbackType));
    }
Esempio n. 10
0
 public static void UploadBundle(string path, string filepath, AssetStoreAPI.UploadBundleCallback callback, AssetStoreClient.ProgressCallback progress)
 {
     AssetStoreClient.UploadLargeFile(path, filepath, null, (AssetStoreResponse resp) =>
     {
         JSONValue jSONValue;
         string str = null;
         AssetStoreAPI.Parse(resp, out str, out jSONValue);
         callback(filepath, str);
     }, progress);
 }
Esempio n. 11
0
    public static void UploadAssets(Package package, string newGUID, string newRootPath, string newProjectpath, string filepath, AssetStoreAPI.DoneCallback callback, AssetStoreClient.ProgressCallback progress)
    {
        string str1 = string.Format("/package/{0}/unitypackage", package.versionId);
        Dictionary <string, string> strs = new Dictionary <string, string>()
        {
            { "root_guid", newGUID },
            { "root_path", newRootPath },
            { "project_path", newProjectpath }
        };

        AssetStoreClient.UploadLargeFile(str1, filepath, strs, (AssetStoreResponse resp) =>
        {
            JSONValue jSONValue;
            if (resp.HttpStatusCode == -2)
            {
                callback("aborted");
                return;
            }

            string str = null;
            AssetStoreAPI.Parse(resp, out str, out jSONValue);
            callback(str);
        }, progress);
    }
Esempio n. 12
0
 private static void Upload(string path, string filepath, AssetStoreAPI.DoneCallback callback, AssetStoreClient.ProgressCallback progress = null)
 {
     AssetStoreClient.Pending pending = AssetStoreClient.CreatePendingUpload(path, path, filepath, (AssetStoreResponse resp) =>
     {
         JSONValue jSONValue;
         string str = null;
         AssetStoreAPI.Parse(resp, out str, out jSONValue);
         callback(str);
     });
     pending.progressCallback = progress;
 }