private void WriteBundlesDatabase() { Console.WriteLine("Writing asset bundles database..."); _bundlesDatabaseBuilder.BuildAssetBundle(Path.Combine(_bundlesPath, "index"), _params.Target); string infoPath = Path.Combine(_params.BundlesLocation, _bundlesDatabaseBuilder.Database.Id + ".txt"); using (StreamWriter writer = File.CreateText(infoPath)) { writer.WriteLine("[" + PlayerSettings.companyName + " - " + PlayerSettings.productName + "]"); writer.WriteLine("Id: " + _bundlesDatabaseBuilder.Database.Id); writer.WriteLine("Version: " + CachingUtils.GetVersionFromId(_bundlesDatabaseBuilder.Database.Id)); writer.WriteLine("Hash: " + BuildUtils.ToHexString(_bundlesDatabaseBuilder.Database.Hash)); writer.WriteLine("Size: " + _bundlesDatabaseBuilder.Database.Size); writer.WriteLine("Created: " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss (K)")); writer.WriteLine("App Version: " + PlayerSettings.bundleVersion); writer.WriteLine("Platform: " + _params.Target.ToString()); writer.WriteLine("Subtarget: " + (_params.Target == BuildTarget.Android ? _params.AndroidSubtarget.ToString() : "Generic")); writer.WriteLine(); foreach (var bundleInfo in _bundles) { writer.WriteLine("[" + bundleInfo.Name + "]"); writer.WriteLine("Filename: " + bundleInfo.Data.Filename); writer.WriteLine("Size: " + bundleInfo.Data.Size); writer.WriteLine("Hash: " + BuildUtils.ToHexString(bundleInfo.Data.Hash)); writer.WriteLine("Cache Name: " + bundleInfo.Data.CacheName); writer.WriteLine("Version: " + CachingUtils.GetVersionFromHash(bundleInfo.Data.Hash)); if (bundleInfo.IsScene) { writer.WriteLine("Scenes:"); foreach (var scene in bundleInfo.AssetsPaths) { writer.WriteLine("\t" + scene + "\t(" + BuildUtils.ToHexString(GetHashForBuildAsset(scene)) + ")"); } } writer.WriteLine("Bundle Assets:"); foreach (var assetPath in bundleInfo.AssetsPaths) { writer.WriteLine("\t" + assetPath + "\t" + GetAssetId(assetPath) + "\t(" + BuildUtils.ToHexString(GetHashForBuildAsset(assetPath)) + ")"); } writer.WriteLine("Dependencies Assets:"); var assetPaths = BuildUtils.GetAssetPathsForObjects(bundleInfo.Dependencies); foreach (var assetPath in assetPaths) { writer.WriteLine("\t" + assetPath + "\t(" + BuildUtils.ToHexString(GetHashForBuildAsset(assetPath)) + ")"); } writer.WriteLine(); } } }
private void AddToDatabase(AssetBundlesDatabase.BundleData bundle, byte[] hash, string bundlePath) { bundle.Filename = Path.GetFileName(bundlePath); using (FileStream stream = File.OpenRead(bundlePath)) { bundle.Size = (int)stream.Length; bundle.Hash = hash; var str = bundle.Filename + "@" + CachingUtils.GetVersionFromHash(bundle.Hash); bundle.CacheName = BuildUtils.ToHexString(BuildUtils.GetASCIIStringHash(str)); } _database.Bundles.Add(bundle); // Update hash, id and size _database.Hash = BuildUtils.Sha1.ComputeHash(_database.Hash.Concat(bundle.Hash).ToArray()); _database.Id = BuildUtils.ToHexString(_database.Hash.Take(4)); _database.Size += bundle.Size; //EditorUtility.SetDirty(_database); }