private static void SetMeshImporterMat(Material mat) { var mainDir = UnityEditorUtility.GetSelectDir(); var dirs = IOUtility.GetAllDir(mainDir); if (dirs != null) { foreach (var dir in dirs) { var fullDir = UnityIOUtility.GetFullPath(dir); //Debug.LogError(dir); var fullpaths = Directory.GetFiles(fullDir); foreach (var item in fullpaths) { SetMeshImporterMat(item, mat); } } } //var objs = AssetDatabase.LoadAllAssetsAtPath(dir); //Debug.LogError(objs.Length); //foreach (var item in objs) //{ // Debug.LogError(item.name); //} }
/// <summary> /// 设置目标目录的打包类型 /// </summary> /// <param name="buildType"></param> private static void SetTargetDirAtildType(AssetBundleBuildType buildType) { var projectInfo = ProjectInfoDati.GetActualInstance(); var assetbundleEditor = AssetBundleEditorDati.GetActualInstance(); locAppId = projectInfo.DevelopProjectName; if (string.IsNullOrEmpty(locAppId)) { UnityEditorUtility.DisplayError("未设置项目名称"); return; } //appHelper = locU3DApp.Helper; if (assetbundleEditor == null) { Debug.LogError($"项目的 AssetBundleSetting 实例未创建 !"); return; } var dirs = UnityEditorUtility.GetSelectDirs(); foreach (var dir in dirs) { if (!dir.StartsWith(projectInfo.ProjectAssetDatabaseDir)) { Debug.LogError($"目标目录不是一个有效的AssetBundle打包目录!"); return; } assetbundleEditor.SetBuildAtTargetBuildType(dir, buildType); if (buildType == AssetBundleBuildType.BuildAtDirTree) // 清理所有子目录的打包配置 { var sonDirs = IOUtility.GetAllDir(dir, null, true, false); foreach (var sonDir in sonDirs) { assetbundleEditor.CleanBuildSettingAtDir(sonDir); } Debug.Log($"目录{dir}已设置为目录树打包,其所有子目录的打包配置都已被清空!"); } } AssetBundleEditorDati.GetSingleDati().Save(); }
private static void SetSonDirAtildType(AssetBundleBuildType buildType, List <string> dirs) { locAppId = UnityEditorUtility.GetLocAppIdAtSelectDir(); locU3DApp = ProjectInfoDati.GetActualInstance(); if (string.IsNullOrEmpty(locAppId)) { UnityEditorUtility.DisplayError("所选择的目录不是一个应用下的有效目录!"); return; } foreach (var dir in dirs) { if (!dir.StartsWith(locU3DApp.ProjectAssetDatabaseDir)) //&& dir.StartsWith(appHelper.StreamingAssetsDir)) { Debug.LogError($"目标目录不是一个有效的AssetBundle打包目录!"); continue; } var assetbundleEditor = AssetBundleEditorDati.GetActualInstance(); if (assetbundleEditor == null) { Debug.Log($"应用{locAppId}没有AssetBundle打包配置!"); return; } assetbundleEditor.SetBuildAtTargetBuildType(dir, buildType); if (buildType == AssetBundleBuildType.BuildAtDirTree) // 清理所有子目录的打包配置 { var sonDirs = IOUtility.GetAllDir(dir, null, true, false); foreach (var sonDir in sonDirs) { assetbundleEditor.CleanBuildSettingAtDir(sonDir); } Debug.Log($"目录{dir}已设置为目录树打包,其所有子目录的打包配置都已被清空!"); } } AssetBundleEditorDati.GetSingleDati().Save(); }
private static void SetTargetDirsBundleIdAndSelectBuild(bool isBuild, bool isSaveSetting) { var selectDir = UnityEditorUtility.GetSelectDir(); var targetApp = UnityEditorUtility.TryGetLocProjectInfoAtDir(selectDir); if (targetApp == null) { UnityEditorUtility.DisplayError("所选择的目录是一个无效目录,必须是一个应用允许打包的目录!"); return; } var dirs = IOUtility.GetAllDir(selectDir); var appAssetBundleSetting = AssetBundleEditorDati.GetActualInstance(); var dirSettings = new List <AssetBundleBuildSetting>(); foreach (var dir in dirs) { var setting = appAssetBundleSetting.GetSetting(dir); if (setting == null) { continue; } dirSettings.Add(setting); } AssetBundleBuilder.currentAssetBundleInfo = AssetBundleBuilder.GetAppAssetBundleInfo(targetApp.DevelopProjectName); for (int i = 0; i < dirSettings.Count; i++) { EditorUtility.DisplayProgressBar("设置 AB 包名", $"正在设置 {dirSettings[i].Dir} 文件夹的 AB 包名", i * 1.0f / dirSettings.Count); AssetBundleBuilder.SetBundleIdAndSelectIsBuild(dirSettings[i], isBuild, true, isSaveSetting); } EditorUtility.ClearProgressBar(); AssetBundleBuilder.SaveCurrentAppAssetBundleInfo(); AssetBundleEditorDati.GetSingleDati().Save(); }