/// <summary> /// Are the texture rules optimal (do they conform to our project settings?) /// </summary> /// <returns>A list of textures that violate our validation policies</returns> /// <param name="allTextures">All textures to check.</param> public static List <Texture> ValidateTextures(IEnumerable <Texture> allTextures) { List <Texture> violatedTextures = new List <Texture>(); foreach (var texture in allTextures) { if (!EditorUtility.IsPersistent(texture)) { continue; } string assetPath = AssetDatabase.GetAssetPath(texture); bool isInternalAsset = string.IsNullOrEmpty(assetPath); if (isInternalAsset) { continue; } TextureImporter textureImporter = TextureImporter.GetAtPath(assetPath) as TextureImporter; if (!textureImporter) { Debug.LogError(string.Format("Asset '{0}' with path '{1}' had no texture importer (weird, skipping)", texture.name, assetPath), texture); continue; } string formatErrors = GetCompressFormatErrors(textureImporter); if (!string.IsNullOrEmpty(formatErrors)) { Debug.LogError("Asset '" + assetPath + "' has non-optimal format: " + formatErrors, texture); violatedTextures.Add(texture); continue; } var bestFolderRule = ProjectImportSettings.FindBestRule(textureImporter, ProjectImportSettings.GetAllTextureFolderRules()); string errorString = GetTextureFolderRuleErrors(bestFolderRule, textureImporter); if (!string.IsNullOrEmpty(errorString)) { Debug.LogError("Asset '" + assetPath + "' violates its folder rule: " + bestFolderRule.folderPath + " (" + errorString + ")", texture); violatedTextures.Add(texture); continue; } } return(violatedTextures); }
private static void ReimportAssetByRule() { string path = ""; string[] prefabPath; if (AssetMenu.CheckSelectionFileDir(ref path)) { string[] guids = AssetDatabase.FindAssets("t:texture2D", new string[] { path }); string[] guids2 = AssetDatabase.FindAssets("t:Model", new string[] { path }); prefabPath = new string[guids.Length + guids2.Length]; for (int i = 0; i < guids.Length; i++) { prefabPath[i] = AssetDatabase.GUIDToAssetPath(guids[i]); } for (int i = 0; i < guids2.Length; i++) { prefabPath[guids.Length + i] = AssetDatabase.GUIDToAssetPath(guids2[i]); } } else { prefabPath = new string[Selection.objects.Length]; for (int i = 0; i < prefabPath.Length; i++) { prefabPath[i] = AssetDatabase.GetAssetPath(Selection.objects[i]); } } for (int i = 0; i < prefabPath.Length; i++) { if (!prefabPath[i].EndsWith(".FBX") && !prefabPath[i].EndsWith(".tga") && !prefabPath[i].EndsWith(".png") && !prefabPath[i].EndsWith(".jpg")) { continue; } EditorUtility.DisplayProgressBar("按照设置重新导入", prefabPath[i], (float)(i + 1) / prefabPath.Length); AssetImporter ai = AssetImporter.GetAtPath(prefabPath[i]); if (null != ai) { ProjectImportSettings.ApplyRulesToObject(ai); ai.SaveAndReimport(); } } EditorUtility.ClearProgressBar(); }
private static string CheckMesh(Mesh mesh, bool bSkin, GameObject modelRoot) { //var mesh = meshFilter.sharedMesh; bool bShouldBatch = false; if (EditorUtility.IsPersistent(mesh)) { string assetPath = AssetDatabase.GetAssetPath(mesh); var modelImporter = ModelImporter.GetAtPath(assetPath); if (!modelImporter) { return(string.Format("Mesh in '{0}' did not contain a ModelImporter. It cannot be performance tested.", assetPath)); } // Find the best rule, if none, we just assume we passed... var bestRule = ProjectImportSettings.FindBestRule(modelImporter, ProjectImportSettings.GetAllModelFolderRules()); if (bestRule == null) { return(null); } CheckModelByBestRule(modelImporter, bestRule, modelRoot, assetPath); if (mesh.vertexCount > bestRule.maxVertices) { return(string.Format("Mesh in '{0}' violated its folder rule setting '{1}' for maxVertices ({2} > {3})", assetPath, bestRule.folderPath, mesh.vertexCount, bestRule.maxVertices)); } if (mesh.bindposes.Length != 0 && mesh.bindposes.Length > bestRule.maxBones) { return(string.Format("Mesh in '{0}' violated its folder rule setting '{1}' for bones ({2} > {3})", assetPath, bestRule.folderPath, mesh.bindposes.Length, bestRule.maxBones)); } if (mesh.boneWeights.Length != 0) { if (!CheckBoneWeight(mesh.boneWeights, bestRule.maxBoneWeights)) { return(string.Format("Mesh in '{0}' violated its folder rule setting '{1}' for boneWeight too much", assetPath, bestRule.folderPath)); } } bShouldBatch = bestRule.shouldBatch; } bool bShouldBatchRegardless = (mesh.vertexCount <= NUM_VERTICES_WHERE_IT_SHOULD_BATCH_REGARDLESS_OF_SETTINGS); if (bShouldBatch || bShouldBatchRegardless) { if (!WillGameObjectBatch(modelRoot)) { if (bShouldBatch) { return(string.Format("Mesh in '{0}' was required to batch by rule but it does not batch.", mesh.name)); } else { return(string.Format("Mesh in '{0}' should batch due to its very small vertex count, but will not!", mesh.name)); } } } return(null); }