static void BuildAssetBundle2(string platform) { AssetBundlePathTools.CreateFolder(AssetBundlePathConst.assetBundleOutPath); if (!Directory.Exists(AssetBundlePathConst.assetBundleOutPath)) { Debug.Log($" path={AssetBundlePathConst.assetBundleOutPath} is not exist"); return; } List <AssetBundleBuild> buildMap = FileInfo2AssetConst();//new List<AssetBundleBuild>(); if (buildMap == null) { Debug.Log($"not config assetbundle"); return; } Debug.Log($"{buildMap.Count} + fisrt{ buildMap[0].assetBundleName},path={buildMap[0].assetNames.Length}"); AssetBundleManifest assetBundleManifest = BuildPipeline.BuildAssetBundles(AssetBundlePathConst.assetBundleOutPath, buildMap.ToArray(), recommandBundleOptions, EditorUserBuildSettings.activeBuildTarget); // List<AssetBundleLoadInfo> assetBundleDependInfos = new List<AssetBundleLoadInfo>(); if (assetBundleManifest != null) { CopyToStreamingAsset(assetBundleManifest); } }
static void CopyToPersistentDataPath() { var sourcesPath = Path.Combine(Application.streamingAssetsPath, AssetBundlePathConst.RuntimeAssetsRoot); var targetPath = Path.Combine(Application.persistentDataPath, AssetBundlePathConst.RuntimeAssetsRoot); AssetBundlePathTools.CreateFolder(targetPath); AssetBundlePathTools.CopyDirectory(sourcesPath, targetPath); // var filename = "Version.txt"; // AssetBundlePathTools.CopyFile(Path.Combine(sourcesPath, filename),Path.Combine(targetPath, filename)); }
static void BuildAssetBundle(string platform) { AssetBundlePathTools.CreateFolder(AssetBundlePathConst.assetBundleOutPath); if (!Directory.Exists(AssetBundlePathConst.assetBundleOutPath)) { Debug.Log($" path={AssetBundlePathConst.assetBundleOutPath} is not exist"); return; } BuildTarget buildTarget = EditorUserBuildSettings.activeBuildTarget; AssetBundleManifest assetBundleManifest = BuildPipeline.BuildAssetBundles(AssetBundlePathConst.assetBundleOutPath, recommandBundleOptions, buildTarget); if (assetBundleManifest != null) { CopyToStreamingAsset(assetBundleManifest); } }
static void CopyToStreamingAsset(AssetBundleManifest assetBundleManifest) { AssetBundleVersionWraper versionWraper = new AssetBundleVersionWraper(); Dictionary <string, AssetBundleLoadInfo> loadInfos = new Dictionary <string, AssetBundleLoadInfo>(); var buildMap = assetBundleManifest.GetAllAssetBundles(); foreach (var bundleBuild in buildMap) { var bundleName = bundleBuild; loadInfos.Add(bundleName, new AssetBundleLoadInfo { Name = bundleName, Hash = assetBundleManifest.GetAssetBundleHash(bundleName).ToString(), Dependancies = assetBundleManifest.GetAllDependencies(bundleName).ToList(), Md5Str = AssetUtils.BuildFileMd5(Path.Combine(AssetBundlePathConst.assetBundleOutPath, bundleName)), }); } foreach (var loadInfo in loadInfos) { Debug.Log($"json={loadInfo.Value.Dependancies.Count},key={loadInfo.Value.Hash}"); } versionWraper.LoadInfos = loadInfos; var sourcesPath = AssetBundlePathConst.assetBundleOutPath; var targetPath = Path.Combine(Application.streamingAssetsPath, AssetBundlePathConst.RuntimeAssetsRoot); AssetBundlePathTools.CreateFolder(targetPath); AssetBundlePathTools.CopyDirectory(sourcesPath, targetPath); JsonSerializerSettings setting = new JsonSerializerSettings(); setting.NullValueHandling = NullValueHandling.Ignore; string json = JsonConvert.SerializeObject(versionWraper, setting); Debug.Log($"json={json}"); string filePath = Path.Combine(targetPath, "Version.txt"); File.WriteAllText(filePath, json, Encoding.UTF8); }