static void LoadVersions(Dictionary <string, BundleVersion> versions) { if (File.Exists(versionsFilePath)) { TextReader reader = new StreamReader(versionsFilePath); if (reader != null) { string line = null; while ((line = reader.ReadLine()) != null) { string[] fields = line.Split(':'); BundleVersion v = new BundleVersion(); v.bundle = fields [0]; v.hash = Hash128.Parse(fields [1]); v.version = int.Parse(fields [2]); versions [v.bundle] = v; } reader.Close(); } } }
public void Build() { var time = System.DateTime.Now.TimeOfDay.TotalSeconds; AssetDatabase.RemoveUnusedAssetBundleNames(); var allAssetBundleNames = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < allAssetBundleNames.Length; i++) { var item = allAssetBundleNames [i]; if (System.IO.Directory.Exists(item)) { Debug.LogError(item + " Is Directory."); } } AssetDatabase.RemoveUnusedAssetBundleNames(); allAssetBundleNames = AssetDatabase.GetAllAssetBundleNames(); if (allAssetBundleNames.Length > 0) { bundles = new Bundle[allAssetBundleNames.Length]; map.Clear(); for (int i = 0; i < allAssetBundleNames.Length; i++) { var item = allAssetBundleNames [i]; bundles [i] = new Bundle(); bundles [i].name = item; bundles [i].assets = AssetDatabase.GetAssetPathsFromAssetBundle(item); map [item] = bundles [i]; } EditorUtility.SetDirty(this); } var importer = AssetImporter.GetAtPath(EXPORT_PATH + ASSET_NAME); if (importer != null) { importer.assetBundleName = ASSETBUNDLE_NAME; } var elasped = System.DateTime.Now.TimeOfDay.TotalSeconds - time; Dictionary <string, BundleVersion> versions = new Dictionary <string, BundleVersion> (); LoadVersions(versions); var assetBundleManifest = BuildAssetBundles(); if (assetBundleManifest != null) { foreach (var item in allAssetBundleNames) { var hash = assetBundleManifest.GetAssetBundleHash(item); BundleVersion version = null; if (!versions.TryGetValue(item, out version)) { version = new BundleVersion(); version.bundle = item; version.hash = hash; version.version = 1; versions [item] = version; } else { if (!version.hash.Equals(hash)) { version.hash = hash; version.version++; } } } Debug.Log("assetBundleManifest.GetHashCode: " + assetBundleManifest.GetHashCode()); } SaveVersions(versions); Debug.Log("[AssetManifest] Build with " + elasped + " seconds."); }