using System.IO; using System; using UnityEditor; using UnityEngine; using System.Collections.Generic; using System.Text.RegularExpressions; namespace BFEditor.Resource { public class MeshToolWindow : EditorWindow { Vector2 scrollPosition = new Vector2(100, 100); string vertexCountStr = "300"; string trianglesStr = "300"; MeshToolWindow() { this.titleContent = new GUIContent("模型顶点/三角面数检查"); MeshTool.Clear(); } void OnGUI() { DrawButton(); DrawResult(); } void DrawButton() { GUILayout.Space(15); var style = new GUIStyle(GUI.skin.button); style.fontSize = 15; style.alignment = TextAnchor.MiddleCenter; GUILayout.BeginHorizontal(); if (GUILayout.Button("检查", style, GUILayout.Width(100), GUILayout.Height(26))) { CheckAll(); } GUILayout.Label("最小顶点数", GUILayout.Width(100)); vertexCountStr = GUILayout.TextField(vertexCountStr, GUILayout.Width(100)); GUILayout.Label("最小三角面数", GUILayout.Width(100)); trianglesStr = GUILayout.TextField(trianglesStr, GUILayout.Width(100)); if (GUILayout.Button("输出excel文档到桌面", style, GUILayout.Width(200), GUILayout.Height(26))) { Dictionary> results = MeshTool.results; List infoList = new List(); infoList.Add("文件名\t类型\t路径\t顶点数\t模型面数"); int vertexCount = int.Parse(vertexCountStr); int triangles = int.Parse(trianglesStr); foreach(string path in results.Keys) { string modelType = "特效"; if(path.Contains("assets/arts/models/characters")) { modelType = "角色"; } else if(path.Contains("ssets/arts/models/maincity")) { modelType = "主城"; } else if(path.Contains("ssets/arts/models/weapon")) { modelType = "武器"; } string lineStr = Path.GetFileName(path) + "\t" + modelType + "\t" + path; bool needShow = true; foreach(string k in results[path].Keys) { if(k == "vertexCount" && results[path][k] <= vertexCount) { needShow = false; break; } if(k == "triangles" && results[path][k] <= triangles) { needShow = false; break; } lineStr += "\t" + (results[path][k]).ToString(); } if(!needShow) { continue; } lineStr.Replace('/', '\\'); infoList.Add(lineStr); } var desktopDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory); var xlsxPath = System.IO.Path.Combine(desktopDir, "模型&面数统计.xlsx"); string txtPath = desktopDir + "/test.txt"; File.WriteAllLines(txtPath, infoList.ToArray()); string relitivePath = Application.dataPath; relitivePath = relitivePath.Remove(relitivePath.Length - 6, 6); string pythonToolPath = relitivePath + "Tools/tranexcel_new"; BFEditorUtils.RunCommond("python", "txt2excel.py " + txtPath + " " + xlsxPath, pythonToolPath); File.Delete(txtPath); } GUILayout.EndHorizontal(); GUILayout.Space(15); } void CheckAll() { MeshTool.Check(); } void DrawResult() { if(MeshTool.CheckedOver) { GUILayout.BeginHorizontal(); GUILayout.Label("资源", GUILayout.Width(150)); GUILayout.Label("路径", GUILayout.Width(450)); GUILayout.Label("顶点&三角面数", GUILayout.Width(450)); GUILayout.EndHorizontal(); scrollPosition = GUILayout.BeginScrollView( scrollPosition, GUILayout.Width(900), GUILayout.Height(800)); Dictionary> results = MeshTool.results; int vertexCount = int.Parse(vertexCountStr); int triangles = int.Parse(trianglesStr); foreach(string path in results.Keys) { bool needShow = true; string str = ""; foreach(string k in results[path].Keys) { if(k == "vertexCount" && results[path][k] <= vertexCount) { needShow = false; break; } if(k == "triangles" && results[path][k] <= triangles) { needShow = false; break; } str = str + k + " " + results[path][k].ToString() + " "; } if(!needShow) { continue; } GUILayout.BeginHorizontal(); GameObject go = (GameObject)EditorGUILayout.ObjectField("", AssetDatabase.LoadAssetAtPath(path),typeof(GameObject), true, GUILayout.Width(150)); GUILayout.TextField(path, GUILayout.Width(450)); GUILayout.BeginVertical(); GUILayout.TextField(str); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Label("", GUILayout.Width(100)); } GUILayout.EndScrollView(); } } void OnDestroy() { MeshTool.Clear(); } public static void ShowMeshToolWindow() { var window = (MeshToolWindow)GetWindowWithRect(typeof(MeshToolWindow), new Rect(Screen.width / 2, Screen.height / 2, 900, 800)); window.Show(); } } }