public static void CheckSelectedUVCount() { CCheckTools.ClearLogList(); int curIndex = 0; int fileCount; string[] filePath = null; string defaultPath = ""; CCheckTools.GetSelectedFilePath(ref filePath, ref defaultPath); if (filePath != null && filePath.Length > 0) { fileCount = filePath.Length; foreach (string s in filePath) { curIndex++; CCheckTools.DisplayProgressBar("检查中", s, curIndex / (float)fileCount); CheckUVByPath(s); } CCheckTools.ClearProgressBar(); } else if (!string.IsNullOrEmpty(defaultPath)) { CheckUVByPath(defaultPath); } else { Debug.LogError("未选择任何文件"); } CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice2); }
public static void CheckAllMaterials() { CCheckTools.ClearLogList(); countStr.Clear(); repeatStr.Clear(); string[] files = Directory.GetFiles(CPath.AssetsApp, "*.*", SearchOption.AllDirectories); int fileCount = files.Length; int curIndex = 0; foreach (string f in files) { CCheckTools.DisplayProgressBar("处理中", f, curIndex / (float)fileCount); curIndex++; CheckMaterials(f); } foreach (string s in countStr) { CCheckTools.AddErrorInfo(s); } foreach (string s in repeatStr) { CCheckTools.AddErrorInfo(s); } CCheckTools.ClearProgressBar(); CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice1); }
public static void CheckModelFiles(bool bmodify) { foreach (string type in modelFilter) { string[] files = Directory.GetFiles(CPath.Assets, "*." + type, SearchOption.AllDirectories); int index = 0; int totalCount = files.Length; foreach (string f in files) { CCheckTools.DisplayProgressBar("检查所有" + type + "文件读写权限", f, index / (float)totalCount); string path = f.Replace('\\', '/'); ModelImporter imp = AssetImporter.GetAtPath(path) as ModelImporter; if (imp != null && imp.isReadable == true) { Debug.LogError(path); if (bmodify) { imp.isReadable = false; AssetDatabase.ImportAsset(path); } } index++; } CCheckTools.ClearProgressBar(); } }
public static void CheckSelectedCharacterTris() { bShowDetail = true; CCheckTools.ClearLogList(); string[] filePath = null; string defaultPath = ""; CCheckTools.GetSelectedFilePath(ref filePath, ref defaultPath, "*.FBX"); if (filePath != null && filePath.Length > 0) { foreach (string s in filePath) { CheckCharacterTris(s); } } else if (!string.IsNullOrEmpty(defaultPath)) { CheckCharacterTris(defaultPath); } else { Debug.LogError("未选择任何文件"); } CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice2); }
private static void CheckMaterialsByRoot(GameObject root) { if (root == null) { return; } Renderer[] render = root.GetComponentsInChildren <Renderer>(); string logStr = ""; foreach (Renderer r in render) { if (r is ParticleSystemRenderer) { continue; } logStr = CCheckTools.GetCompletePath(r.transform); if (SceneOrPrefab == 1) { logStr = "Scene:" + SceneManager.GetActiveScene().name + "->" + logStr; } if (r.sharedMaterials != null) { if (r.sharedMaterials.Length > 4) { countStr.Add(logStr + ":material count=" + r.sharedMaterials.Length); } if (MaterialsRepeat(r.sharedMaterials)) { repeatStr.Add(logStr + ":material repeat"); } } } }
private static void CheckSceneLights(string path) { if (!File.Exists(path) || !path.EndsWith(".unity")) { return; } mode_realTime = 0; mode_baked = 0; mode_mixed = 0; detailInfo = ""; path = path.Replace('\\', '/'); Scene scene = EditorSceneManager.OpenScene(path, OpenSceneMode.Single); int totalcount = 0; foreach (GameObject root in scene.GetRootGameObjects()) { totalcount += GetChildTris(root); } path = path.Substring(0, path.Length - ".unity".Length); CCheckTools.AddLogInfo("场景“" + path + "”灯光总数:" + totalcount + "(Baked:" + mode_baked + " RealTime:" + mode_realTime + " Mixed:" + mode_mixed + ")"); if (string.IsNullOrEmpty(detailInfo)) { CCheckTools.AddLogInfo(detailInfo); } }
public static void CheckSelectedScenesLights() { bShowDetail = true; CCheckTools.ClearLogList(); int curIndex = 0; string[] files = null; string defaultPath = ""; CCheckTools.GetSelectedFilePath(ref files, ref defaultPath, "*.unity"); if (files != null && files.Length > 0) { int fileCount = files.Length; foreach (string s in files) { curIndex++; CCheckTools.DisplayProgressBar("检查中", s, curIndex / (float)fileCount); CheckSceneLights(s); } CCheckTools.ClearProgressBar(); } else if (!string.IsNullOrEmpty(defaultPath)) { CheckSceneLights(defaultPath); } else { Debug.LogError("未选择任何文件"); } CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice2); }
private static void CheckSelectedFileByType(string searchOption) { CCheckTools.ClearLogList(); int index = 0; string[] filePath = null; string defaultPath = ""; CCheckTools.GetSelectedFilePath(ref filePath, ref defaultPath, searchOption); if (filePath != null && filePath.Length > 0) { int fileCount = filePath.Length; foreach (string s in filePath) { index++; CCheckTools.DisplayProgressBar("检查中", index + "/" + fileCount + " " + s, index / (float)fileCount); //CheckFile(s); CheckChineseCharOrSpaceInFlieName(s); } CCheckTools.ClearProgressBar(); } else if (!string.IsNullOrEmpty(defaultPath)) { CheckFile(defaultPath); } else { Debug.LogError("未选择任何文件"); } CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, "选中目录下,所有类型为" + searchOption + "且文件名包含空格的文件:"); }
public static void CheckAllCharacterTris() { bShowDetail = false; CCheckTools.ClearLogList(); string[] files = Directory.GetFiles(CPath.AssetsAppArtCharacter, "*.FBX", SearchOption.AllDirectories); foreach (string f in files) { CheckCharacterTris(f); } CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice1); }
public static void CheckRenameFile() { Debug.Log(notice1); string[] filePath = null; string defaultPath = ""; int curIndex = 0; CCheckTools.GetSelectedFilePath(ref filePath, ref defaultPath); if (filePath != null && filePath.Length > 0) { fileCount = filePath.Length; string[] objArray = new string[filePath.Length]; //筛选文件并获取文件路径 int count = 0; //待检查文件总数 for (int i = 0; i < filePath.Length; i++) { if (IsCheck(filePath[i])) { objArray[count++] = filePath[i]; } } fileCount = count * 2; curIndex = count; CCheckTools.DisplayProgressBar("检查中", "快速排序...", 1 / 2.0f); //先排序,再找重名 QuickSort(ref objArray, 0, count - 1); for (int i = 0; i < count; i++) { curIndex++; CCheckTools.DisplayProgressBar("检查中", objArray[i], curIndex / (float)fileCount); if (i + 1 < count && GetObjLowerFileName(objArray[i]).Equals(GetObjLowerFileName(objArray[i + 1]))) { string log = objArray[i]; while (i + 1 < count && GetObjLowerFileName(objArray[i]).Equals(GetObjLowerFileName(objArray[i + 1]))) { log = log + "==" + objArray[i + 1]; i++; curIndex++; } Debug.LogError(log); } } CCheckTools.ClearProgressBar(); } else { Debug.LogError("你没有选择文件夹或只选择了一个文件"); } }
//根据路径检查triangles private static void CheckSceneTris(string path) { if (!File.Exists(path) || !path.EndsWith(".unity")) { return; } detailInfo = ""; path = path.Replace('\\', '/'); Scene scene = EditorSceneManager.OpenScene(path, OpenSceneMode.Single); int totalcount = 0; foreach (GameObject root in scene.GetRootGameObjects()) { totalcount += GetChildTris(root); } path = path.Substring(0, path.Length - ".unity".Length); if (totalcount <= 20000) { CCheckTools.AddLogInfo("场景“" + path + "”三角面总数:" + totalcount); if (!string.IsNullOrEmpty(detailInfo)) { detailInfo.Remove(detailInfo.Length - 1, 1); CCheckTools.AddLogInfo(detailInfo); } } else if (totalcount > 20000 && totalcount <= 100000) { CCheckTools.AddWarningInfo("场景“" + path + "”三角面总数:" + totalcount); if (!string.IsNullOrEmpty(detailInfo)) { detailInfo.Remove(detailInfo.Length - 1, 1); CCheckTools.AddWarningInfo(detailInfo); } } else if (totalcount > 100000) { CCheckTools.AddErrorInfo("场景“" + path + "”三角面总数:" + totalcount); if (!string.IsNullOrEmpty(detailInfo)) { detailInfo.Remove(detailInfo.Length - 1, 1); CCheckTools.AddErrorInfo(detailInfo); } } }
public static void CheckALLUVCount() { CCheckTools.ClearLogList(); string[] files = Directory.GetFiles(CPath.AssetsApp, "*.*", SearchOption.AllDirectories); int fileCount = files.Length; int curIndex = 0; foreach (string f in files) { CCheckTools.DisplayProgressBar("处理中", f, curIndex / (float)fileCount); curIndex++; CheckUVByPath(f); } CCheckTools.ClearProgressBar(); CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice1); }
//[MenuItem("Assets/检查工具/检查所有场景的同名物体", false, 340)] //[MenuItem("检查工具/检查所有场景的同名物体", false, 340)] public static void CheckRenameComponentInAllScenes() { int fileCount; int index = 0; string[] files = Directory.GetFiles(CPath.AssetsAppArtScenes, "*.unity", SearchOption.AllDirectories); fileCount = files.Length; list = new List <GameObject>(); foreach (string f in files) { CCheckTools.DisplayProgressBar("处理中", f, index / (float)fileCount); index++; CheckRenameComponent(f); } CCheckTools.ClearProgressBar(); }
public static void CheckAllCharacterBones() { CCheckTools.ClearLogList(); string[] files = Directory.GetFiles(CPath.AssetsAppArtCharacter, "*.FBX", SearchOption.AllDirectories); int fileCount = files.Length; int index = 0; foreach (string f in files) { CCheckTools.DisplayProgressBar("处理中", f, index / (float)fileCount); index++; CheckCharacterBones(f); } CCheckTools.ClearProgressBar(); CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice1); }
private static void CheckAllFileByType(string searchOption) { CCheckTools.ClearLogList(); string[] files = Directory.GetFiles(defaultPathRoot, searchOption, SearchOption.AllDirectories); int fileCount = files.Length; int index = 0; foreach (string f in files) { CCheckTools.DisplayProgressBar("检查中", index + "/" + fileCount + " " + f, index / (float)fileCount); index++; //CheckFile(f); CheckChineseCharOrSpaceInFlieName(f); } CCheckTools.ClearProgressBar(); CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, "所有类型为" + searchOption + "且文件名包含空格或汉字的文件:"); }
// 工具基本不使用,先注释掉菜单 //[MenuItem("Assets/程序/检查工具/检查选中目录下包含的文件类型", false, 02010041)] //[MenuItem("程序/检查工具/检查选中目录下包含的文件类型", false, 02010041)] public static void CheckFileType() { CCheckTools.ClearLogList(); int fileCount; int curIndex = 0; object[] objArray = Selection.GetFiltered(typeof(DefaultAsset), SelectionMode.Assets); if (null == objArray || objArray.Length == 0) { Debug.LogError("没有选中任何文件夹"); return; } string path = AssetDatabase.GetAssetPath(objArray[0] as Object); string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories); fileCount = files.Length; List <string> typeList = new List <string>(); foreach (string fp in files) { CCheckTools.DisplayProgressBar("检查中", fp, curIndex / (float)fileCount); curIndex++; if (fp.IndexOf('.') < 0) { continue; } string type = fp.Split('.')[fp.Split('.').Length - 1]; if (type.IndexOf('/') >= 0 || type.IndexOf('\\') >= 0) { continue; //排除xxx.xxx/yyy文件 } if (!typeList.Exists(s => s.Equals(type))) { typeList.Add(type); } } foreach (string s in typeList) { CCheckTools.AddLogInfo(s); } CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile("文件类型", "", CCheckTools.EFileType.txt); CCheckTools.ClearProgressBar(); }
private static void CheckCharacterBones(string path) { if (!File.Exists(path) || !path.EndsWith(".FBX")) { return; } path = path.Replace('\\', '/'); if (Ignore(path)) { return; } GameObject rootGO = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path) as GameObject; if (null == rootGO) { return; } path = path.Substring(0, path.Length - ".FBX".Length); int totalCount = GetBonesCountByRoot(rootGO); if (path.EndsWith("_H")) { if (totalCount > 100) { CCheckTools.AddErrorInfo(path + "->count:" + totalCount); } else { CCheckTools.AddLogInfo(path + "->count:" + totalCount); } } else { if (totalCount > 50) { CCheckTools.AddErrorInfo(path + "->count:" + totalCount); } else { CCheckTools.AddLogInfo(path + "->count:" + totalCount); } } }
private static void CheckFile(string path) { if (!File.Exists(path) || path.EndsWith("meta")) { return; } path = path.Replace('\\', '/'); string[] temp = path.Split('/'); string name = temp[temp.Length - 1]; foreach (char c in name) { if (c.Equals(' ')) { CCheckTools.AddLogInfo(path); break; } } }
public static void CheckAllImageSize() { mImageList.Clear(); CCheckTools.ClearLogList(); string[] files = Directory.GetFiles(CPath.AssetsApp, "*.*", SearchOption.AllDirectories); int fileCount = files.Length; int curIndex = 0; foreach (string f in files) { CCheckTools.DisplayProgressBar("处理中", f, curIndex / (float)fileCount); curIndex++; CheckImageSize(f); } CCheckTools.ClearProgressBar(); CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice1); //savaInExcel(mImageList, CPath.OutPutPath, csvName); savaInExcel(mImageList, Application.dataPath + "/ToolsOutput/", mCsvName); }
private static void CheckCharacterTris(string path) { if (!File.Exists(path) || !path.EndsWith(".FBX")) { return; } detailInfo = ""; path = path.Replace('\\', '/'); if (Ignore(path)) { return; } GameObject rootGO = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path) as GameObject; path = path.Substring(0, path.Length - ".FBX".Length); CCheckTools.AddLogInfo("模型“" + path + "”三角面总数:" + GetChildTris(rootGO)); if (!string.IsNullOrEmpty(detailInfo)) { CCheckTools.AddLogInfo(detailInfo); } }
public static void CheckAllScenesLights() { Debug.Log(notice1); bShowDetail = false; CCheckTools.ClearLogList(); int fileCount; string[] files = Directory.GetFiles(CPath.AssetsAppArtScenes, "*.unity", SearchOption.AllDirectories); fileCount = files.Length; int index = 0; foreach (string f in files) { CCheckTools.DisplayProgressBar("处理中", f, index / (float)fileCount); index++; CheckSceneLights(f); } CCheckTools.ClearProgressBar(); CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice1); }
private static void CheckImageSize(string path) { if (!File.Exists(path) || !path.EndsWith(".png") && !path.EndsWith(".psd") && !path.EndsWith(".tga")) { return; } path = path.Replace('\\', '/'); UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path); if (null == obj) { return; } Texture tex = obj as Texture; if (null != tex) { if (tex.width > MaxSize || tex.height > MaxSize) { CCheckTools.AddErrorInfo(path + ":" + tex.width + "*" + tex.height); } else if (tex.width > WarningSize || tex.height > WarningSize) { CCheckTools.AddWarningInfo(path + ":" + tex.width + "*" + tex.height); } if (path.Contains(mSceneFlag)) { int idx = path.IndexOf(mSceneFlag) + mSceneFlag.Length; path = path.Substring(idx); string[] pathArr = path.Split('/'); if (pathArr.Length > 0) { path = pathArr[0]; } string sceneName = path; ImageInfo imgInfo = new ImageInfo(sceneName, tex.name, tex.height, tex.width); mImageList.Add(imgInfo); } } }
public static void CheckColorByRoot(Transform root) { if (root == null) { return; } MeshFilter mf = root.GetComponent <MeshFilter>(); SkinnedMeshRenderer smr = root.GetComponent <SkinnedMeshRenderer>(); if (mf != null && mf.sharedMesh != null) { if (mf.sharedMesh.colors.Length > 0 || mf.sharedMesh.colors32.Length > 0) { string logStr = CCheckTools.GetCompletePath(root); CCheckTools.AddLogInfo(logStr); } } for (int i = 0; i < root.transform.childCount; i++) { CheckColorByRoot(root.transform.GetChild(i)); } }
//[MenuItem("Assets/检查工具/检查选中场景的同名物体", false, 340)] //[MenuItem("检查工具/检查选中场景的同名物体", false, 340)] public static void CheckRenameComponentInSelectedScenes() { int fileCount;; int curIndex = 0; list = new List <GameObject>(); string[] filePath = null; string defaultPath = ""; CCheckTools.GetSelectedFilePath(ref filePath, ref defaultPath, "*.unity"); if (filePath != null && filePath.Length > 0) { fileCount = filePath.Length; foreach (string s in filePath) { curIndex++; CCheckTools.DisplayProgressBar("检查中", s, curIndex / (float)fileCount); CheckRenameComponent(s); } CCheckTools.ClearProgressBar(); } }
public static void CheckSelectedImageSize() { mImageList.Clear(); CCheckTools.ClearLogList(); int fileCount = 0; int curIndex = 0; string[] filePath = null; string defaultPath = ""; CCheckTools.GetSelectedFilePath(ref filePath, ref defaultPath); if (filePath != null && filePath.Length > 0) { fileCount = filePath.Length; foreach (string s in filePath) { curIndex++; CCheckTools.DisplayProgressBar("检查中", s, curIndex / (float)fileCount); CheckImageSize(s); } CCheckTools.ClearProgressBar(); } else if (!string.IsNullOrEmpty(defaultPath)) { CheckImageSize(defaultPath); } else { Debug.LogError("未选择任何文件"); } CCheckTools.LogAll(); CCheckTools.WriteAllInfoToFile(fileName, notice1); //savaInExcel(mImageList, CPath.OutPutPath, csvName); savaInExcel(mImageList, Application.dataPath + "/ToolsOutput/", mCsvName); }
public static void CheckUVByRoot(Transform root) { if (root == null) { return; } MeshFilter mf = root.GetComponent <MeshFilter>(); SkinnedMeshRenderer smr = root.GetComponent <SkinnedMeshRenderer>(); int count = 0; if (mf != null && mf.sharedMesh != null) { if (mf.sharedMesh.uv.Length > 0) { count++; } if (mf.sharedMesh.uv2.Length > 0) { count++; } if (mf.sharedMesh.uv3.Length > 0) { count++; } if (mf.sharedMesh.uv4.Length > 0) { count++; } if (mf.sharedMesh.uv5.Length > 0) { count++; } if (mf.sharedMesh.uv6.Length > 0) { count++; } if (mf.sharedMesh.uv7.Length > 0) { count++; } if (mf.sharedMesh.uv8.Length > 0) { count++; } } if (smr != null && smr.sharedMesh != null) { if (smr.sharedMesh.uv.Length > 0) { count++; } if (smr.sharedMesh.uv2.Length > 0) { count++; } if (smr.sharedMesh.uv3.Length > 0) { count++; } if (smr.sharedMesh.uv4.Length > 0) { count++; } if (smr.sharedMesh.uv5.Length > 0) { count++; } if (smr.sharedMesh.uv6.Length > 0) { count++; } if (smr.sharedMesh.uv7.Length > 0) { count++; } if (smr.sharedMesh.uv8.Length > 0) { count++; } } if (count >= 2) { string logStr = CCheckTools.GetCompletePath(root); CCheckTools.AddLogInfo(logStr + ":uv Count=" + count); } for (int i = 0; i < root.transform.childCount; i++) { CheckUVByRoot(root.transform.GetChild(i)); } }