예제 #1
0
        public bool IsCached(string url)
        {
#pragma warning disable 0618
            return(Caching.IsVersionCached(url, Cdn.GetFileVersion(url)));

#pragma warning restore 0618
        }
예제 #2
0
        public static void LoadVersion(string cdnPath, Action <Exception> callback)
        {
            string url = Cdn.ToFullPath(cdnPath);

            Web.noCache.GetBytes(url, b =>
            {
                if (b != null)
                {
                    LineParser parser = new LineParser(false);
                    char[] separator  = new char[] { VER_SEPARATOR };
                    foreach (string line in parser.Parse(b, Encoding.UTF8))
                    {
                        string[] tok = line.SplitEx(separator);
                        if (tok.Length >= 2)
                        {
                            int ver = 0;
                            int.TryParse(tok[1], out ver);
                            versions.Add(Cdn.ToFullPath(tok[0]), ver);
                        }
                    }
                    callback(null);
                }
                else
                {
                    callback(new Exception("Can't access " + cdnPath));
                }
            });
        }
예제 #3
0
        public void DownloadList(IList <string> listFiles, Action <Exception> callback)
        {
            InitDownloader();
            step = DownloadStep.Null;
#if !UNITY_WEBGL
            listDownloader.unzipMethod = unzipMethod;
#endif
            log.Debug("Downloading list files {0}", listFiles.Join(","));
            listDownloader.BeginDownload(Cdn.Path, listFiles, e =>
            {
                if (e == null)
                {
                    Exception ex = null;
                    // merge list files
                    List <string> files = new List <string>();
                    int count           = 0;
                    foreach (string f in listFiles)
                    {
                        Web.noCache.GetBytes(Cdn.ToFullPath(f), b => {
                            count++;
                            if (b != null)
                            {
                                StreamReader r = new StreamReader(new MemoryStream(b));
                                while (!r.EndOfStream)
                                {
                                    string line = r.ReadLine();
                                    //                              #if UNITY_WEBGL
                                    //                              line = PathUtil.ReplaceExtension(line, FileTypeEx.ASSET_BUNDLE);
                                    //                              #endif
                                    files.Add(line);
                                }
                            }
                            else
                            {
                                ex = new Exception(f);
                            }
                            if (count == listFiles.Count)
                            {
                                if (ex == null)
                                {
                                    DownloadFiles(files, callback);
                                }
                                else
                                {
                                    step = DownloadStep.Canceled;
                                    callback(ex);
                                }
                            }
                        });
                    }
                }
                else
                {
                    step = DownloadStep.Canceled;
                    callback(e);
                }
            });
        }
예제 #4
0
        private string GetEditorAssetPath <T>(string url) where T : Object
        {
            if (url.IsEmpty())
            {
                return(string.Empty);
            }
            string u = url.ToUnixPath();

            if (u.StartsWith(Application.dataPath))
            {
                u = url.Substring(Application.dataPath.Length);
            }
            else
            {
                u = Cdn.ToRelativePath(u);
            }

            if (typeof(T) == typeof(Object))
            {
                u = FindAsset(u, ".prefab", ".asset");
            }
            else if (typeof(T).IsAssignableFrom(typeof(Texture)))
            {
                u = FindAsset(u, FileType.Image.GetExt());
            }
            else if (typeof(T).IsAssignableFrom(typeof(GameObject)))
            {
                u = FindAsset(u, FileType.Prefab.GetExt());
            }
            else if (typeof(T).IsAssignableFrom(typeof(Animation)))
            {
                u = FindAsset(u, FileType.Anim.GetExt());
            }
            else if (typeof(T).IsAssignableFrom(typeof(Material)))
            {
                u = FindAsset(u, FileType.Material.GetExt());
            }
            else if (typeof(T).IsAssignableFrom(typeof(TextAsset)))
            {
                u = FindAsset(u, FileType.Text.GetExt());
            }
            else if (typeof(T).IsAssignableFrom(typeof(AudioClip)))
            {
                u = FindAsset(u, FileType.Audio.GetExt());
            }
            else if (typeof(T).IsAssignableFrom(typeof(AssetBundle)))
            {
                u = FindAsset(u, FileTypeEx.ASSET_BUNDLE);
            }
            else
            {
                // Error Handling
                u = FindAsset(u, ".anim", ".prefab", ".mat", ".png", ".jpg", ".tga", ".bmp", ".bytes", ".txt", ".csv", ".asset");
            }
            return("Assets/" + u);
        }
예제 #5
0
 public bool IsCached(string url)
 {
     url = Cdn.ToRelativePath(url);
     if (url.Is(FileType.Asset))
     {
         return(FindAsset(url, ".asset", ".prefab", ".png", ".jpg", ".dds", ".tga", ".tiff", ".tif", ".psd", ".ogg", ".mp3", ".wav", ".unity", ".mat", ".anim", ".txt", ".bytes", ".csv") != null);
     }
     else
     {
         string localPath = PathUtil.Combine(Application.dataPath, url);
         return(File.Exists(localPath));
     }
 }
예제 #6
0
        public WWW CreateWWW(string url)
        {
            string parent   = PathUtil.GetParent(url);
            string filename = WWW.EscapeURL(Path.GetFileName(url));

            if (caching)
            {
                int version = Cdn.GetFileVersion(url);
                filename = PathUtil.ReplaceExtension(filename, FileTypeEx.ASSET_BUNDLE);
                string uri = PathUtil.Combine(parent, filename);
                if (log.IsLoggable(LogType.Log))
                {
#pragma warning disable 0618
                    log.Debug("{0} (ver {1}): {2}", uri, version, Caching.IsVersionCached(uri, version)? "Cached": "Download & Cache");
#pragma warning restore 0618
                }
                return(WWW.LoadFromCacheOrDownload(uri, version));
            }
            else
            {
                string uri = PathUtil.Combine(parent, filename);
                return(new WWW(uri));
            }
        }
예제 #7
0
 private string ToLocalPath(string url)
 {
     return(PathUtil.Combine(Application.dataPath, Cdn.ToRelativePath(url)));
 }