/// <summary> /// 设置 Bundle 包名 /// 设置 AssetId To Bundle 映射信息 /// </summary> /// <param name="dirSetting"></param> /// <param name="paths"></param> /// <param name="bundleId"></param> /// <param name="plusFileName"></param> private static void SetAssetBundleId(AssetBundleBuildSetting dirSetting, List <string> paths, string bundleId = null, bool plusFileName = false) { var appBundleInfo = currentAssetBundleInfo; var bundleIds = new List <string>(); foreach (var path in paths) { var assetId = Path.GetFileNameWithoutExtension(path); if (string.IsNullOrEmpty(assetId)) { Debug.LogError($"路径{path}获取文件名失败!"); continue; } var assetLowerId = assetId.ToLower(); var finalBundleId = bundleId ?? assetLowerId; if (plusFileName) { finalBundleId = string.Format("{0}_{1}", finalBundleId, 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; } }
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; } }