/// <summary> /// 生成ResourceList.json信息 /// </summary> private void CreateResourceListJsonFile(AssetBundleManifest manifest) { if (IsCreateResourceList) { var abList = ABUtility.CreateABListFromManifest(manifest); string jsonStr = JsonMapper.ToJson(abList); using (StreamWriter sw = new StreamWriter(Path.Combine(OutputPath, "ResourceList.json"))) { sw.Write(jsonStr); } } }
private void Create() { if (string.IsNullOrEmpty(Version)) { throw new InvalidDataException("必须填写版本号"); } if (Version == GetCurrentVersion()) { Debug.LogWarning("不使用新的版本号将导致新的版本无法被察觉, 从而导致无法升级"); } if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); var manifest = BuildPipeline.BuildAssetBundles(OutputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); if (manifest) { CreateResourceListJsonFile(manifest); CreateVersionJsonFile(); ABLocalManager.ClearEmtry(OutputPath); } else { Clear(); } } else { var ab = AssetBundle.LoadFromFile(Path.Combine(OutputPath, "AssetBundles")); var oldManifest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); var oldABList = ABUtility.CreateABListFromManifest(oldManifest); ab.Unload(true); var newManifest = BuildPipeline.BuildAssetBundles(OutputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); if (newManifest) { CreateResourceListJsonFile(newManifest); CreateVersionJsonFile(); var newABList = ABUtility.CreateABListFromManifest(newManifest); var deleteList = ABUtility.GetDeleteABList(oldABList, newABList); foreach (var name in deleteList) { File.Delete(Path.Combine(OutputPath, name)); File.Delete(Path.Combine(OutputPath, name + ".manifest")); } ABLocalManager.ClearEmtry(OutputPath); } else { Clear(); } } }