using System.Globalization; using System.Text; using UnityEditor; using UnityEngine; public static class FixAndDiagnoseMaleExplorer { public static string Diagnose() { const string fbx = "Assets/Bundles/Characters/MaleExplorer/MaleExplorer.fbx"; var sb = new StringBuilder(); var importer = AssetImporter.GetAtPath(fbx) as ModelImporter; if (importer != null) { sb.AppendLine($"globalScale={importer.globalScale} useFileScale={importer.useFileScale} " + $"bakeAxisConversion={importer.bakeAxisConversion} " + $"meshCompression={importer.meshCompression}"); } foreach (var obj in AssetDatabase.LoadAllAssetsAtPath(fbx)) { if (obj is not Mesh mesh) continue; var vs = mesh.vertices; var min = vs[0]; var max = vs[0]; for (var i = 1; i < vs.Length; i++) { min = Vector3.Min(min, vs[i]); max = Vector3.Max(max, vs[i]); } var size = max - min; sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "mesh={0} verts={1} min=({2:F6},{3:F6},{4:F6}) max=({5:F6},{6:F6},{7:F6}) size=({8:F6},{9:F6},{10:F6})", mesh.name, vs.Length, min.x, min.y, min.z, max.x, max.y, max.z, size.x, size.y, size.z)); } return sb.ToString(); } public static string FixImportAndPrefab() { const string fbx = "Assets/Bundles/Characters/MaleExplorer/MaleExplorer.fbx"; var importer = AssetImporter.GetAtPath(fbx) as ModelImporter; if (importer == null) return "no importer"; // Blender 已按米导出时,关掉 Unity 默认 0.01 厘米换算 importer.globalScale = 1f; importer.useFileScale = false; importer.bakeAxisConversion = true; importer.materialImportMode = ModelImporterMaterialImportMode.None; importer.SaveAndReimport(); // 重建 Prefab return SetupM3Character.SetupAll() + " | " + Diagnose(); } }