public AssetBundleBuildSetting GetSetting(string path) { path = UnityIOUtility.GetAssetsPath(path); var setting = BundleDirSettings.Find(s => s.Dir == path); return(setting); }
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> /// 清理应用的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> /// 尝试获取指定目录所在的应用配置。 /// </summary> /// <param name="dir"></param> /// <returns></returns> public static ProjectInfo TryGetLocProjectInfoAtDir(string dir) { var fullDir = UnityIOUtility.GetFullPath(dir); var appSetting = ProjectInfoDati.GetActualInstance(); var appRootDir = appSetting.ProjectRootDir; if (fullDir.StartsWith(appRootDir)) { return(appSetting); } return(null); }
private Dictionary <string, Type> GetAppRxModelTypeDic(string appId) { if (RxTypeDict.ContainsKey(appId)) { return(RxTypeDict[appId]); } var appAsm = UnityIOUtility.GetUnityAssembly(appId + "Play"); var typeDic = ReflectUtility.GetTypeDictionary <IYuLegoUIRxModel>(appAsm); var typeDic2 = ReflectUtility.GetTypeDictionary <IYuLegoScrollViewRxModel>(appAsm); typeDic.Combin(typeDic2); RxTypeDict.Add(appId, typeDic); return(typeDic); }
/// <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; } }
/// <summary> /// 获取当前选中资源完整路径 /// </summary> /// <returns></returns> public static string GetSelectFileFullPath() { return(UnityIOUtility.GetFullPath(GetSelectFileAssetsPath())); }
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(); } }