コード例 #1
0
        protected virtual IEnumerator DoAnalyzeDownloadList(IProgressPromise <float, List <BundleInfo> > promise, BundleManifest manifest)
        {
            List <BundleInfo> downloads = new List <BundleInfo>();

            BundleInfo[] bundleInfos = manifest.GetAll();
            float        last        = Time.realtimeSinceStartup;
            int          length      = bundleInfos.Length;

            for (int i = 0; i < bundleInfos.Length; i++)
            {
                BundleInfo info = bundleInfos[i];
                if (Time.realtimeSinceStartup - last > 0.15f)
                {
                    yield return(null);

                    last = Time.realtimeSinceStartup;
                }
                promise.UpdateProgress(i + 1 / (float)length);
                if (BundleUtil.Exists(info))
                {
                    continue;
                }

                downloads.Add(info);
            }
            promise.SetResult(downloads);
        }
コード例 #2
0
ファイル: BundleBuilder.cs プロジェクト: Hengle/hotdemo
        public virtual List <BundleInfo> GetDeltaUpdates(BundleManifest previousVersion, BundleManifest currentVersion, bool compareCRC = false)
        {
            List <BundleInfo> bundles = new List <BundleInfo>();

            Dictionary <string, BundleInfo> dict = new Dictionary <string, BundleInfo>();

            foreach (BundleInfo bundle in previousVersion.GetAll())
            {
                dict.Add(bundle.FullName, bundle);
            }

            foreach (BundleInfo bundle in currentVersion.GetAll())
            {
                BundleInfo previous;
                if (!dict.TryGetValue(bundle.FullName, out previous))
                {
                    bundles.Add(bundle);
                    continue;
                }

                if (previous.Hash.Equals(bundle.Hash) && previous.Encoding.Equals(bundle.Encoding) && (!compareCRC || previous.CRC == bundle.CRC))
                {
                    continue;
                }

                bundles.Add(bundle);
            }
            return(bundles);
        }
コード例 #3
0
ファイル: BundleBuilder.cs プロジェクト: Hengle/hotdemo
 /// <summary>
 /// Check the loop reference.
 /// </summary>
 /// <param name="bundleManifest">Bundle manifest.</param>
 protected virtual void CheckAssetBundle(BundleManifest bundleManifest)
 {
     BundleInfo[] bundles = bundleManifest.GetAll();
     foreach (BundleInfo bundle in bundles)
     {
         bundleManifest.GetDependencies(bundle.Name, true);
     }
 }
コード例 #4
0
ファイル: BundleBuilder.cs プロジェクト: Hengle/hotdemo
        public virtual BundleManifest CopyAssetBundle(BundleManifest manifest, 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
            {
                foreach (BundleInfo bundleInfo in manifest.GetAll())
                {
                    if (bundleFilter != null && !bundleFilter.IsValid(bundleInfo))
                    {
                        continue;
                    }

                    FileInfo   srcFile    = new FileInfo(System.IO.Path.Combine(src.FullName, bundleInfo.Filename).Replace(@"\", "/"));
                    byte[]     data       = File.ReadAllBytes(srcFile.FullName);
                    BundleData bundleData = new BundleData(bundleInfo, data);
                    if (bundleModifierChain != null && bundleModifierChain.Count > 0)
                    {
                        foreach (IBundleModifier modifier in bundleModifierChain)
                        {
                            modifier.Modify(bundleData);
                        }
                    }

                    FileInfo destFile = new FileInfo(System.IO.Path.Combine(dest.FullName, bundleInfo.Filename).Replace(@"\", "/"));
                    if (destFile.Exists)
                    {
                        destFile.Delete();
                    }

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

                    File.WriteAllBytes(destFile.FullName, bundleData.Data);
                }
                return(manifest);
            }
            catch (System.Exception e)
            {
                throw new System.Exception(string.Format("Copy AssetBundles failure from {0} to {1}.", src.FullName, dest.FullName), e);
            }
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
ファイル: BundleBuilder.cs プロジェクト: lovoror/UnityDemo
        public virtual void Build(string outputPath, BuildTarget buildTarget, BuildAssetBundleOptions options, string version, List <IBundleModifier> bundleModifierChain = null)
        {
            if (EditorUserBuildSettings.activeBuildTarget != buildTarget)
            {
                if (!EditorUserBuildSettings.SwitchActiveBuildTarget(BuildPipeline.GetBuildTargetGroup(buildTarget), buildTarget))
                {
                    throw new System.Exception("Switch BuildTarget failure.");
                }
            }

            if (string.IsNullOrEmpty(outputPath))
            {
                throw new System.ArgumentNullException("outputPath");
            }

            if (string.IsNullOrEmpty(version))
            {
                throw new System.ArgumentNullException("version");
            }


            string platformOutput = this.GetPlatformOutput(outputPath, buildTarget);
            string genOutput      = this.GetGenOutput(outputPath, buildTarget);
            string versionOutput  = this.GetVersionOutput(outputPath, buildTarget, version);

            if (((options & BuildAssetBundleOptions.ForceRebuildAssetBundle) > 0) && Directory.Exists(genOutput))
            {
                Directory.Delete(genOutput, true);
            }

            if (Directory.Exists(versionOutput))
            {
                Directory.Delete(versionOutput, true);
            }

            if (!Directory.Exists(genOutput))
            {
                Directory.CreateDirectory(genOutput);
            }

            if (!Directory.Exists(versionOutput))
            {
                Directory.CreateDirectory(versionOutput);
            }

            AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(genOutput, options, buildTarget);

            if (manifest == null)
            {
                throw new System.Exception("Build failure.");
            }

#if UNITY_5_6_OR_NEWER
            if ((options & BuildAssetBundleOptions.DryRunBuild) > 0)
            {
                return;
            }
#endif

            try
            {
                AssetDatabase.StartAssetEditing();

                BundleManifest    lastVersionBundleManifest = this.GetPreviousBundleManifest(outputPath, buildTarget, version);
                List <BundleInfo> lastBundles = new List <BundleInfo>();
                if (lastVersionBundleManifest != null)
                {
                    lastBundles.AddRange(lastVersionBundleManifest.GetAll());
                }

                BundleManifest bundleManifest = this.CreateBundleManifest(genOutput, manifest, version);

                bundleManifest = this.CopyAssetBundle(bundleManifest, new DirectoryInfo(genOutput), new DirectoryInfo(versionOutput), bundleModifierChain);
                File.WriteAllText(string.Format("{0}/{1}", versionOutput, BundleSetting.ManifestFilename), bundleManifest.ToJson());

                File.WriteAllText(string.Format("{0}/{1}_{2}.csv", platformOutput, ManifestPrefix, version), this.ToCSV(lastBundles.ToArray(), bundleManifest.GetAll()));
            }
            finally
            {
                AssetDatabase.StopAssetEditing();
            }
        }