public static void Report(AnalyzeProjectInfo project, List <string> roots) { List <string> files = new List <string>(); string[] arr; foreach (string root in roots) { if (!Directory.Exists(root)) { continue; } arr = Directory.GetFiles(root, "*.Prefab", SearchOption.AllDirectories); files.AddRange(arr); } for (int i = 0; i < files.Count; i++) { string path = files[i]; Object o = AssetDatabase.LoadAssetAtPath(path, typeof(Object)); string guid = AssetDatabase.AssetPathToGUID(path); AnalyzeObjectInfo objectInfo = project.Get(guid); if (objectInfo == null) { objectInfo = new AnalyzeObjectInfo(); objectInfo.guid = guid; objectInfo.path = path; objectInfo.type = o.GetType(); objectInfo.fileInfo = AnalyzeFileAsset.Generate(o); AnalyzeFileInfo f = objectInfo.fileInfo; objectInfo.propertys = new List <KeyValuePair <string, object> >(); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.MaterialCount, f.MaterialCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.Texture2DCount, f.Texture2DCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.TotalTriangleCount, f.TotalTriangleCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.TotalVertexCount, f.TotalVertexCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.BonesCount, f.BonesCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.ParticleSystemCount, f.ParticleSystemCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.TotalForecastParticleCount, f.TotalForecastParticleCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.TotalForecastTrianglesCount, f.TotalForecastTrianglesCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.MeshFilterCount, f.MeshFilterCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.SkinnedMeshRendererCount, f.SkinnedMeshRendererCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.MeshRendererCount, f.MeshRendererCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.AnimatorCount, f.AnimatorCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.TransformCount, f.TransformCount)); objectInfo.propertys.Add(new KeyValuePair <string, object>(AnalyzePropertys.ObjectCount, f.ObjectCount)); project.Add(objectInfo); } } }
public static void Report(AnalyzeProjectInfo project) { string[] guids = AssetDatabase.FindAssets("t:texture2D", null); Type type = typeof(Texture2D); foreach (string guid in guids) { AnalyzeObjectInfo objectInfo = project.Get(guid); if (objectInfo == null) { objectInfo = new AnalyzeObjectInfo(); objectInfo.guid = guid; objectInfo.type = type; objectInfo.path = AssetDatabase.GUIDToAssetPath(guid); var importer = AssetImporter.GetAtPath(objectInfo.path) as TextureImporter; if (importer == null) { continue; } string format = "未知"; int w, h; var tex = GetTextureSize(importer, out w, out h) as Texture2D; if (tex != null) { format = tex.format.ToString(); } objectInfo.propertys = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(AnalyzePropertys.Width, w), new KeyValuePair <string, object>(AnalyzePropertys.Height, h), new KeyValuePair <string, object>(AnalyzePropertys.IsPow2Size, IsPow2Size(w, h)), new KeyValuePair <string, object>(AnalyzePropertys.MaxTextureSize, importer.maxTextureSize), new KeyValuePair <string, object>(AnalyzePropertys.ReadWrite, importer.isReadable), new KeyValuePair <string, object>(AnalyzePropertys.MiniMap, importer.mipmapEnabled), new KeyValuePair <string, object>(AnalyzePropertys.TextureFormat, format), new KeyValuePair <string, object>(AnalyzePropertys.TextureCompression, importer.textureCompression.ToString()), new KeyValuePair <string, object>(AnalyzePropertys.SpriteImportMode, importer.spriteImportMode.ToString()), }; project.Add(objectInfo); } } }
public static void Report(AnalyzeProjectInfo project) { string[] guids = AssetDatabase.FindAssets("t:Mesh", null); Type type = typeof(Mesh); foreach (string guid in guids) { AnalyzeObjectInfo objectInfo = project.Get(guid); if (objectInfo == null) { objectInfo = new AnalyzeObjectInfo(); objectInfo.guid = guid; objectInfo.type = type; objectInfo.path = AssetDatabase.GUIDToAssetPath(guid); var importer = AssetImporter.GetAtPath(objectInfo.path) as ModelImporter; if (importer == null) { continue; } var mesh = AssetDatabase.LoadAssetAtPath <Mesh>(objectInfo.path); objectInfo.propertys = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(AnalyzePropertys.VertexCount, mesh.vertexCount), new KeyValuePair <string, object>(AnalyzePropertys.TriangleCount, (mesh.triangles.Length / 3f)), new KeyValuePair <string, object>(AnalyzePropertys.SubMeshCount, mesh.subMeshCount), new KeyValuePair <string, object>(AnalyzePropertys.ScaleFactor, importer.globalScale), new KeyValuePair <string, object>(AnalyzePropertys.UseFileUnits, importer.useFileUnits), new KeyValuePair <string, object>(AnalyzePropertys.FileScale, importer.fileScale), new KeyValuePair <string, object>(AnalyzePropertys.MeshCompression, importer.meshCompression.ToString()), new KeyValuePair <string, object>(AnalyzePropertys.ReadWrite, importer.isReadable), new KeyValuePair <string, object>(AnalyzePropertys.OptimizeMesh, importer.optimizeMesh), new KeyValuePair <string, object>(AnalyzePropertys.OptimizeGameObjects, importer.optimizeGameObjects), new KeyValuePair <string, object>(AnalyzePropertys.GenerateCollider, importer.addCollider), new KeyValuePair <string, object>(AnalyzePropertys.ImportBlendShapes, importer.importBlendShapes), new KeyValuePair <string, object>(AnalyzePropertys.ImportMaterials, importer.importMaterials), new KeyValuePair <string, object>(AnalyzePropertys.TransformPathsCount, importer.transformPaths.Length), new KeyValuePair <string, object>(AnalyzePropertys.ExtraExposedTransformPathsCount, importer.extraExposedTransformPaths.Length), }; project.Add(objectInfo); } } }
public static void CreateAndFillWorksheet <T>(ExcelWorksheets wss, AnalyzeProjectInfo project, string sortKey) { Type type = typeof(T); string[] arr = type.Name.Split('.'); string typeName = arr[arr.Length - 1]; List <AnalyzeObjectInfo> list = project.GetList <T>(); if (list.Count == 0) { return; } CreateAndFillWorksheet(wss, list, typeName, sortKey); }
public static void GenerateAnalyzeProjectMenu() { AnalyzeProjectInfo project = new AnalyzeProjectInfo(); AnalyzeProjectEditorTexture.Report(project); AnalyzeProjectEditorMesh.Report(project); AnalyzeProjectInfo unitProject = new AnalyzeProjectInfo(); AnalyzeProjectEditorForUnit.Report(unitProject, AnalyzeSettings.Instance.unitRoots); AnalyzeProjectInfo fxProject = new AnalyzeProjectInfo(); AnalyzeProjectEditorForUnit.Report(fxProject, AnalyzeSettings.Instance.fxRoots); AnalyzeProjectInfo uiProject = new AnalyzeProjectInfo(); AnalyzeProjectEditorForUnit.Report(uiProject, AnalyzeSettings.Instance.uiPrefabRoots); project.Dict2List(); if (!Directory.Exists(outRoot)) { Directory.CreateDirectory(outRoot); } string json = JsonUtility.ToJson(project, true); File.WriteAllText(outFile_data, json); File.WriteAllText(outFile_data_js, "var guidData = " + json); string xlsx = outFile_xlsx; AnalyzeProjectEditorSaveXLSX.Save(xlsx, project, unitProject, fxProject, uiProject); xlsx = Path.GetFullPath(xlsx); Shell.RevealInFinder(xlsx); OpenAssetSettings.Instance.OpenFile(xlsx); Debug.Log(outFile_data); }
public static void Save(string path, AnalyzeProjectInfo project, AnalyzeProjectInfo unitProject, AnalyzeProjectInfo fxProject, AnalyzeProjectInfo uiProject) { var xlsx = new FileInfo(path); using (var package = new ExcelPackage(xlsx)) { //Texture2D CreateAndFillWorksheet <Texture2D>(package.Workbook.Worksheets, project, AnalyzePropertys.Width); //Mesh CreateAndFillWorksheet <Mesh>(package.Workbook.Worksheets, project, AnalyzePropertys.TriangleCount); //UI List <AnalyzeObjectInfo> list = uiProject.GetList <GameObject>(); CreateAndFillWorksheet(package.Workbook.Worksheets, list, "UI", AnalyzePropertys.TotalForecastTrianglesCount); Dictionary <string, bool> textureGuidDict = new Dictionary <string, bool>(); Dictionary <string, bool> meshGuidDict = new Dictionary <string, bool>(); foreach (AnalyzeObjectInfo item in list) { List <Ihaiu.Editors.AnalyzeObjectInfo> mlist = item.fileInfo.GetList <Texture2D>(); foreach (Ihaiu.Editors.AnalyzeObjectInfo v in mlist) { if (!textureGuidDict.ContainsKey(v.guid)) { textureGuidDict.Add(v.guid, true); } } mlist = item.fileInfo.GetList <Mesh>(); foreach (Ihaiu.Editors.AnalyzeObjectInfo v in mlist) { if (!meshGuidDict.ContainsKey(v.guid)) { meshGuidDict.Add(v.guid, true); } } } list = new List <AnalyzeObjectInfo>(); foreach (var kvp in textureGuidDict) { if (project.guidDict.ContainsKey(kvp.Key)) { list.Add(project.guidDict[kvp.Key]); } } CreateAndFillWorksheet(package.Workbook.Worksheets, list, "UI图片", AnalyzePropertys.Width); list = new List <AnalyzeObjectInfo>(); foreach (var kvp in meshGuidDict) { if (project.guidDict.ContainsKey(kvp.Key)) { list.Add(project.guidDict[kvp.Key]); } } CreateAndFillWorksheet(package.Workbook.Worksheets, list, "UI Mesh", AnalyzePropertys.TriangleCount); // 动态图片 list = new List <AnalyzeObjectInfo>(); List <string> files = new List <string>(); string[] arr; foreach (string root in AnalyzeSettings.Instance.imageRoots) { if (!Directory.Exists(root)) { continue; } arr = Directory.GetFiles(root, "*.*", SearchOption.AllDirectories) .Where(s => Path.GetExtension(s).ToLower() != ".meta" && Path.GetFileName(s).ToLower() != ".ds_store").ToArray(); files.AddRange(arr); } for (int i = 0; i < files.Count; i++) { string guid = AssetDatabase.AssetPathToGUID(files[i]); if (project.guidDict.ContainsKey(guid)) { list.Add(project.guidDict[guid]); } } CreateAndFillWorksheet(package.Workbook.Worksheets, list, "动态图片", AnalyzePropertys.TotalForecastTrianglesCount); //FX list = fxProject.GetList <GameObject>(); CreateAndFillWorksheet(package.Workbook.Worksheets, list, "特效", AnalyzePropertys.TotalForecastTrianglesCount); textureGuidDict = new Dictionary <string, bool>(); meshGuidDict = new Dictionary <string, bool>(); foreach (AnalyzeObjectInfo item in list) { List <Ihaiu.Editors.AnalyzeObjectInfo> mlist = item.fileInfo.GetList <Texture2D>(); foreach (Ihaiu.Editors.AnalyzeObjectInfo v in mlist) { if (!textureGuidDict.ContainsKey(v.guid)) { textureGuidDict.Add(v.guid, true); } } mlist = item.fileInfo.GetList <Mesh>(); foreach (Ihaiu.Editors.AnalyzeObjectInfo v in mlist) { if (!meshGuidDict.ContainsKey(v.guid)) { meshGuidDict.Add(v.guid, true); } } } list = new List <AnalyzeObjectInfo>(); foreach (var kvp in textureGuidDict) { if (project.guidDict.ContainsKey(kvp.Key)) { list.Add(project.guidDict[kvp.Key]); } } CreateAndFillWorksheet(package.Workbook.Worksheets, list, "特效贴图", AnalyzePropertys.Width); list = new List <AnalyzeObjectInfo>(); foreach (var kvp in meshGuidDict) { if (project.guidDict.ContainsKey(kvp.Key)) { list.Add(project.guidDict[kvp.Key]); } } CreateAndFillWorksheet(package.Workbook.Worksheets, list, "特效Mesh", AnalyzePropertys.TriangleCount); //Unit list = unitProject.GetList <GameObject>(); CreateAndFillWorksheet(package.Workbook.Worksheets, list, "所有单位", AnalyzePropertys.TotalTriangleCount); textureGuidDict = new Dictionary <string, bool>(); meshGuidDict = new Dictionary <string, bool>(); //Unit -- Hero List <AnalyzeObjectInfo> heroList = new List <AnalyzeObjectInfo>(); Dictionary <string, bool> heroTextureGuidDict = new Dictionary <string, bool>(); Dictionary <string, bool> heroMeshGuidDict = new Dictionary <string, bool>(); //Unit -- Solider List <AnalyzeObjectInfo> soliderList = new List <AnalyzeObjectInfo>(); Dictionary <string, bool> soliderTextureGuidDict = new Dictionary <string, bool>(); Dictionary <string, bool> soliderMeshGuidDict = new Dictionary <string, bool>(); //Unit -- Tower List <AnalyzeObjectInfo> towerList = new List <AnalyzeObjectInfo>(); Dictionary <string, bool> towerTextureGuidDict = new Dictionary <string, bool>(); Dictionary <string, bool> towerMeshGuidDict = new Dictionary <string, bool>(); //Unit -- Other List <AnalyzeObjectInfo> otherList = new List <AnalyzeObjectInfo>(); Dictionary <string, bool> otherTextureGuidDict = new Dictionary <string, bool>(); Dictionary <string, bool> otherMeshGuidDict = new Dictionary <string, bool>(); Dictionary <string, bool> tTextureGuidDict; Dictionary <string, bool> tMeshGuidDict; foreach (AnalyzeObjectInfo item in list) { string name = Path.GetFileName(item.path).ToLower(); if (name.StartsWith("hero_")) { heroList.Add(item); tTextureGuidDict = heroTextureGuidDict; tMeshGuidDict = heroMeshGuidDict; } else if (name.StartsWith("solider_")) { soliderList.Add(item); tTextureGuidDict = soliderTextureGuidDict; tMeshGuidDict = soliderMeshGuidDict; } else if (name.StartsWith("tower_")) { towerList.Add(item); tTextureGuidDict = towerTextureGuidDict; tMeshGuidDict = towerMeshGuidDict; } else { otherList.Add(item); tTextureGuidDict = otherTextureGuidDict; tMeshGuidDict = otherMeshGuidDict; } List <Ihaiu.Editors.AnalyzeObjectInfo> mlist = item.fileInfo.GetList <Texture2D>(); foreach (Ihaiu.Editors.AnalyzeObjectInfo v in mlist) { if (!textureGuidDict.ContainsKey(v.guid)) { textureGuidDict.Add(v.guid, true); } if (!tTextureGuidDict.ContainsKey(v.guid)) { tTextureGuidDict.Add(v.guid, true); } } mlist = item.fileInfo.GetList <Mesh>(); foreach (Ihaiu.Editors.AnalyzeObjectInfo v in mlist) { if (!meshGuidDict.ContainsKey(v.guid)) { meshGuidDict.Add(v.guid, true); } if (!tMeshGuidDict.ContainsKey(v.guid)) { tMeshGuidDict.Add(v.guid, true); } } } CreateAndFillWorksheet(package.Workbook.Worksheets, heroList, "英雄", AnalyzePropertys.TotalTriangleCount); CreateAndFillWorksheet(package.Workbook.Worksheets, soliderList, "士兵", AnalyzePropertys.TotalTriangleCount); CreateAndFillWorksheet(package.Workbook.Worksheets, towerList, "机关", AnalyzePropertys.TotalTriangleCount); CreateAndFillWorksheet(package.Workbook.Worksheets, otherList, "其他单位", AnalyzePropertys.TotalTriangleCount); string[] names = new string[] { "所有单位", "英雄", "士兵", "机关", "其他" }; Dictionary <string, bool>[] textures = new Dictionary <string, bool>[] { textureGuidDict, heroTextureGuidDict, soliderTextureGuidDict, towerTextureGuidDict, otherTextureGuidDict }; Dictionary <string, bool>[] meshs = new Dictionary <string, bool>[] { meshGuidDict, heroMeshGuidDict, soliderMeshGuidDict, towerMeshGuidDict, otherMeshGuidDict }; for (int i = 0; i < names.Length; i++) { list = new List <AnalyzeObjectInfo>(); foreach (var kvp in textures[i]) { if (project.guidDict.ContainsKey(kvp.Key)) { list.Add(project.guidDict[kvp.Key]); } } CreateAndFillWorksheet(package.Workbook.Worksheets, list, names[i] + "~贴图", AnalyzePropertys.Width); list = new List <AnalyzeObjectInfo>(); foreach (var kvp in meshs[i]) { if (project.guidDict.ContainsKey(kvp.Key)) { list.Add(project.guidDict[kvp.Key]); } } CreateAndFillWorksheet(package.Workbook.Worksheets, list, names[i] + "~Mesh", AnalyzePropertys.TriangleCount); } package.Save(); } }