public static void SaveAppAssetBundleInfo(ProjectAssetsToBundleMapInfo bundleInfo) { if (string.IsNullOrEmpty(bundleInfo.LocAppId)) { UnityEditorUtility.DisplayError("应用Id不能为空!"); throw new Exception("应用Id不能为空!"); } var projectInfo = ProjectInfoDati.GetActualInstance(); var localPath = projectInfo.AssetBundleBuildDir + $"{projectInfo.DevelopProjectName}_AssetToBundleMapInfo.bytes"; var bytes = SerializeUtility.Serialize(bundleInfo); IOUtility.WriteAllBytes(localPath, bytes); AssetDatabase.Refresh(); Debug.Log($"应用{bundleInfo.LocAppId}的AssetBundle数据已更新!"); }
private static void SetAssetBundleIdAtSizeAssetBundle(AssetBundleBuildSetting dirSetting, List <string> paths, ProjectAssetsToBundleMapInfo appBundleInfo, string bundleId = null) { var bundleIds = new List <string>(); foreach (var path in paths) { var assetId = Path.GetFileNameWithoutExtension(path); if (assetId == null) { Debug.LogError($"路径{path}获取文件名失败!"); continue; } var assetLowerId = assetId.ToLower(); var finalBundleId = bundleId ?? ($"({IOUtility.GetSomeDirPath(dirSetting.Dir, 3).ToLower()}_{assetLowerId}"); finalBundleId = finalBundleId.ToLower(); if (bundleIds.Contains(finalBundleId)) { bundleIds.Add(finalBundleId); } appBundleInfo.AddMap(assetLowerId, finalBundleId); var assetsPath = UnityIOUtility.GetAssetsPath(path); var importer = AssetImporter.GetAtPath(assetsPath); if (importer == null) { Debug.LogError($"资源{assetsPath}获取导入器失败!"); continue; } dirSetting.UpdateBundleIds(bundleIds); importer.assetBundleName = finalBundleId; importer.assetBundleVariant = ASSETBUNDLE_SHORT_SUFFIX; } }
public static ProjectAssetsToBundleMapInfo GetAppAssetBundleInfo(string appId) { if (string.IsNullOrEmpty(appId)) { UnityEditorUtility.DisplayError("应用Id不能为空!"); throw new Exception("应用Id不能为空!"); } var projectInfo = ProjectInfoDati.GetActualInstance(); var localPath = projectInfo.AssetBundleBuildDir + $"{projectInfo.DevelopProjectName}_AssetToBundleMapInfo.bytes"; if (File.Exists(localPath)) { var bytes = File.ReadAllBytes(localPath); var appBundleInfo = SerializeUtility.DeSerialize <ProjectAssetsToBundleMapInfo>(bytes); return(appBundleInfo); } var newBundleInfo = new ProjectAssetsToBundleMapInfo(); newBundleInfo.LocAppId = appId; return(newBundleInfo); }