示例#1
0
        public virtual BundleManifest GetPreviousBundleManifest(string outputPath, BuildTarget buildTarget, string version)
        {
            FileInfo file = this.GetPreviousBundleManifestFile(outputPath, buildTarget, version);

            if (file == null)
            {
                return(null);
            }
            var json = File.ReadAllText(file.FullName);

            return(BundleManifest.Parse(json));
        }
示例#2
0
        public virtual List <BundleManifest> FindBundleManifests(string outputPath, BuildTarget buildTarget)
        {
            List <BundleManifest> bundles = new List <BundleManifest>();
            List <FileInfo>       files   = this.FindBundleManifestFiles(outputPath, buildTarget);

            if (files.Count == 0)
            {
                return(bundles);
            }

            for (int i = 0; i < files.Count; i++)
            {
                var info = files[i];
                var json = File.ReadAllText(info.FullName);
                bundles.Add(BundleManifest.Parse(json));
            }
            return(bundles);
        }
示例#3
0
        public virtual BundleManifest CopyAssetBundleAndManifest(DirectoryInfo src, DirectoryInfo dest, List <IBundleModifier> bundleModifierChain = null, IBundleFilter bundleFilter = null)
        {
            if (!src.Exists)
            {
                throw new DirectoryNotFoundException(string.Format("Not found the directory '{0}'.", src.FullName));
            }

            try
            {
                string         json     = File.ReadAllText(System.IO.Path.Combine(src.FullName, BundleSetting.ManifestFilename).Replace(@"\", "/"));
                BundleManifest manifest = BundleManifest.Parse(json);
                manifest = this.CopyAssetBundle(manifest, src, dest, bundleModifierChain, bundleFilter);
                if (manifest != null)
                {
                    File.WriteAllText(System.IO.Path.Combine(dest.FullName, BundleSetting.ManifestFilename).Replace(@"\", "/"), manifest.ToJson());
                }
                return(manifest);
            }
            catch (System.Exception e)
            {
                throw new System.Exception(string.Format("Copy AssetBundles failure from {0} to {1}.", src.FullName, dest.FullName), e);
            }
        }
        protected virtual IEnumerator DoDownloadManifest(string relativePath, IProgressPromise <Progress, BundleManifest> promise)
        {
            Progress progress = new Progress();

            promise.UpdateProgress(progress);
            using (WWW www = new WWW(this.GetAbsoluteUri(relativePath)))
            {
                while (!www.isDone)
                {
                    if (www.bytesDownloaded > 0f)
                    {
                        if (progress.TotalSize <= 0)
                        {
                            progress.TotalSize = www.size;
                        }
                        progress.CompletedSize = www.bytesDownloaded;
                        promise.UpdateProgress(progress);
                    }
                    yield return(null);
                }

                progress.CompletedSize = www.bytesDownloaded;
                promise.UpdateProgress(progress);

                if (!string.IsNullOrEmpty(www.error))
                {
                    promise.SetException(new Exception(www.error));
                    yield break;
                }

                try
                {
                    byte[]         data     = www.bytes;
                    BundleManifest manifest = BundleManifest.Parse(Encoding.UTF8.GetString(data));

                    FileInfo file = new FileInfo(BundleUtil.GetStorableDirectory() + relativePath);
                    if (file.Exists)
                    {
                        FileInfo bakFile = new FileInfo(BundleUtil.GetStorableDirectory() + relativePath + ".bak");
                        if (bakFile.Exists)
                        {
                            bakFile.Delete();
                        }

                        file.CopyTo(bakFile.FullName);
                    }

                    if (!file.Directory.Exists)
                    {
                        file.Directory.Create();
                    }

                    File.WriteAllBytes(file.FullName, data);
                    promise.SetResult(manifest);
                }
                catch (IOException e)
                {
                    promise.SetException(e);
                }
            }
        }
        protected virtual IEnumerator DoDownloadManifest(string relativePath, IProgressPromise <Progress, BundleManifest> promise)
        {
            Progress progress = new Progress();

            promise.UpdateProgress(progress);
            byte[] data;
            string path = this.GetAbsoluteUri(relativePath);

#if UNITY_2017_1_OR_NEWER
            using (UnityWebRequest www = new UnityWebRequest(path))
            {
                www.downloadHandler = new DownloadHandlerBuffer();
#if UNITY_2018_1_OR_NEWER
                www.SendWebRequest();
#else
                www.Send();
#endif
                while (!www.isDone)
                {
                    if (www.downloadProgress >= 0)
                    {
                        if (progress.TotalSize <= 0)
                        {
                            progress.TotalSize = (long)(www.downloadedBytes / www.downloadProgress);
                        }
                        progress.CompletedSize = (long)www.downloadedBytes;
                        promise.UpdateProgress(progress);
                    }
                    yield return(null);
                }

                if (!string.IsNullOrEmpty(www.error))
                {
                    promise.SetException(new Exception(www.error));
                    yield break;
                }

                data = www.downloadHandler.data;
            }
#else
            using (WWW www = new WWW(path))
            {
                while (!www.isDone)
                {
                    if (www.bytesDownloaded > 0f)
                    {
                        if (progress.TotalSize <= 0)
                        {
                            progress.TotalSize = (long)(www.bytesDownloaded / www.progress);
                        }
                        progress.CompletedSize = www.bytesDownloaded;
                        promise.UpdateProgress(progress);
                    }
                    yield return(null);
                }

                progress.CompletedSize = www.bytesDownloaded;
                promise.UpdateProgress(progress);

                if (!string.IsNullOrEmpty(www.error))
                {
                    promise.SetException(new Exception(www.error));
                    yield break;
                }

                data = www.bytes;
            }
#endif

            try
            {
                BundleManifest manifest = BundleManifest.Parse(Encoding.UTF8.GetString(data));

                FileInfo file = new FileInfo(BundleUtil.GetReadOnlyDirectory() + relativePath);
                if (file.Exists)
                {
                    FileInfo bakFile = new FileInfo(BundleUtil.GetReadOnlyDirectory() + relativePath + ".bak");
                    if (bakFile.Exists)
                    {
                        bakFile.Delete();
                    }

                    file.CopyTo(bakFile.FullName);
                }

                if (!file.Directory.Exists)
                {
                    file.Directory.Create();
                }

                File.WriteAllBytes(file.FullName, data);
                promise.SetResult(manifest);
            }
            catch (IOException e)
            {
                promise.SetException(e);
            }
        }
        public static IProgressResult <float> Load(this ArchiveContainer container, DirectoryInfo dir, IStreamDecryptor decryptor)
        {
            try
            {
                List <FileInfo> files = new List <FileInfo>();
                foreach (FileInfo file in dir.GetFiles("*", SearchOption.TopDirectoryOnly))
                {
                    if (file.Name.EndsWith(BundleSetting.ManifestFilename))
                    {
                        files.Add(file);
                        continue;
                    }

                    if (file.Name.EndsWith(dir.Name))
                    {
                        files.Add(file);
                        continue;
                    }
                }

                if (files.Count <= 0)
                {
                    throw new Exception("Please select the root directory of the AssetBundle");
                }

                files.Sort((x, y) => y.LastWriteTime.CompareTo(x.LastWriteTime));

                if (files[0].Name.Equals(BundleSetting.ManifestFilename))
                {
                    BundleManifest manifest = BundleManifest.Parse(File.ReadAllText(files[0].FullName, Encoding.UTF8));
                    return(container.LoadAssetBundle(dir.FullName, decryptor, manifest.GetAll()));
                }
                else if (files[0].Name.Equals(dir.Name))
                {
                    List <string> filenames   = new List <string>();
                    string[]      bundleNames = new string[0];
                    var           bundle      = AssetBundleArchive.Load(files[0].FullName);
                    foreach (var archive in bundle.AssetArchives)
                    {
                        ObjectArchive oa = archive as ObjectArchive;
                        if (oa == null)
                        {
                            continue;
                        }

                        foreach (var summary in oa.GetAllObjectInfo())
                        {
                            if (summary.TypeID == TypeID.AssetBundleManifest)
                            {
                                Objects.AssetBundleManifest assetBundleManifest = summary.GetObject <Objects.AssetBundleManifest>();
                                bundleNames = assetBundleManifest.GetAllAssetBundles();
                            }
                        }
                    }

                    foreach (string bundleName in bundleNames)
                    {
                        var fullName = System.IO.Path.Combine(dir.FullName, bundleName.Replace("/", @"\"));
                        filenames.Add(fullName);
                    }
                    bundle.Dispose();

                    //UnityEngine.AssetBundle bundle = UnityEngine.AssetBundle.LoadFromFile(files[0].FullName);
                    //AssetBundleManifest manifest = bundle.LoadAsset<AssetBundleManifest>("assetbundlemanifest");
                    //bundle.Unload(false);
                    //files = new List<FileInfo>();

                    //foreach (string bundleName in manifest.GetAllAssetBundles())
                    //{
                    //    var fullName = System.IO.Path.Combine(dir.FullName, bundleName.Replace("/", @"\"));
                    //    filenames.Add(fullName);
                    //}

                    return(container.LoadAssetBundle(filenames.ToArray()));
                }
                else
                {
                    List <string> filenames = new List <string>();
                    foreach (FileInfo file in dir.GetFiles("*", SearchOption.AllDirectories))
                    {
                        if (file.FullName.EndsWith(BundleSetting.ManifestFilename) || file.FullName.EndsWith(".manifest"))
                        {
                            continue;
                        }

                        filenames.Add(file.FullName);
                    }
                    return(container.LoadAssetBundle(filenames.ToArray()));
                }
            }
            catch (Exception e)
            {
                return(new ImmutableProgressResult <float>(e, 0f));
            }
        }