public AssetBundleBuildSetting GetSetting(string path) { path = UnityIOUtility.GetAssetsPath(path); var setting = BundleDirSettings.Find(s => s.Dir == path); return(setting); }
/// <summary> /// 清理应用的AssetBundle Id。 /// </summary> public static void CleanAllAssetBundleId() { var assetPaths = new List <string>(); var databasePaths = IOUtility.GetPathsContainSonDir( ProjectInfoDati.GetActualInstance().ProjectAssetDatabaseDir); assetPaths.AddRange(databasePaths); foreach (var assetPath in assetPaths) { if (!SelectPath(assetPath)) { continue; } var assetsPath = UnityIOUtility.GetAssetsPath(assetPath); var importer = AssetImporter.GetAtPath(assetsPath); if (importer == null) { continue; } importer.assetBundleName = null; } AssetDatabase.RemoveUnusedAssetBundleNames(); Debug.Log("AssetBundle包Id已清空!"); }
/// <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 YuU3dAppSetting LocU3DApp => YuU3dAppSettingDati.CurrentActual; private void OnEnable() { var rawImage = GetComponent <YuLegoRawImage>(); if (rawImage.mainTexture.name != "UnityWhite") { return; } var jpgFullPath = /*LocU3DApp.Helper.OriginRawImageDir + rawImageSrc+*/ ".jpg"; var jpgAssetsPath = UnityIOUtility.GetAssetsPath(jpgFullPath); var texture2D = AssetDatabaseUtility.LoadAssetAtPath <Texture2D>(jpgAssetsPath); if (texture2D == null) { var pngFullPath = /*LocU3DApp.Helper.OriginRawImageDir + rawImageSrc + */ ".png"; var pngAssetsPath = UnityIOUtility.GetAssetsPath(pngFullPath); texture2D = AssetDatabaseUtility.LoadAssetAtPath <Texture2D>(pngAssetsPath); } rawImage.texture = texture2D; }
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; } }
private static void SetMeshImporterMat(string fullPath, Material mat) { if (fullPath.EndsWith(".meta")) { return; } var path = UnityIOUtility.GetAssetsPath(fullPath); var obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); if (obj == null) { return; } var importer = ModelImporter.GetAtPath(AssetDatabase.GetAssetPath(obj)) as ModelImporter; if (importer != null) { var renders = obj.GetComponentsInChildren <Renderer>(); string matName = null; foreach (var item in renders) { foreach (var matItem in item.sharedMaterials) { if (matItem != null) { matName = matItem.name; break; } } if (matName != null) { break; } } if (matName == null) { return; } importer.importMaterials = true; importer.materialLocation = ModelImporterMaterialLocation.InPrefab; importer.SaveAndReimport(); var map = importer.GetExternalObjectMap(); List <AssetImporter.SourceAssetIdentifier> list = new List <AssetImporter.SourceAssetIdentifier>(); foreach (var item in map) { //Debug.LogError(item.Key.name + " --- " + item.Key.type); if (item.Key.type == mat.GetType()) { list.Add(item.Key); } } foreach (var item in list) { importer.RemoveRemap(item); importer.AddRemap(item, mat); } foreach (var item in renders) { foreach (var matItem in item.sharedMaterials) { if (matItem != null) { matName = matItem.name; importer.AddRemap(new AssetImporter.SourceAssetIdentifier(mat.GetType(), matName), mat); } } } Debug.Log("完成mesh的Importer Materials操作:" + path); importer.SaveAndReimport(); } }