少年修仙传客户端基础资源
client_Wu Xijin
2018-08-14 31c2cebbccba45a00a755981dd6d0cdd0a0459e9
Assets/Editor/Tool/FBXCheck.cs
@@ -5,82 +5,82 @@
using System;
using System.IO;
public class FBXCheck
{
    static List<string> logs = new List<string>();
public class FBXCheck
{
    static List<string> logs = new List<string>();
    [MenuItem("Assets/角色、NPC 模型检查")]
    public static void LoadMesh()
    {
        var assets = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
        var total = assets.Length;
        var index = 0;
        var meshCount = 0;
        var normalCount = 0;
        var errorCount = 0;
        logs.Clear();
        logs.Add(StringUtility.Contact("序号", "\t", "资源名", "\t", "顶点数", "\t", "三角面"));
        try
        {
            foreach (var asset in assets)
            {
                var assetPath = AssetDatabase.GetAssetPath(asset);
                if (!assetPath.Contains("@"))
                {
                    var mesh = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Mesh));
                    if (mesh != null)
                    {
                        var count = ((Mesh)mesh).vertices.Length;
                        var triangles = ((Mesh)mesh).triangles.Length / 3;
                        var countStandard = 2500;
                        var trianglesStandard = 2600;
                        if (mesh.name.Contains("M") || mesh.name.Contains("N"))
                        {
                            countStandard = 2000;
                            trianglesStandard = 2000;
                        }
                        if (count > countStandard || triangles > trianglesStandard)
                        {
                            Debug.LogErrorFormat("{0}文件-->:顶点数:{1},三角面数:{2}", assetPath, count, triangles);
                            errorCount++;
                        }
                        else
                        {
                            Debug.LogFormat("{0}文件-->:顶点数:{1},三角面数:{2}", assetPath, count, triangles);
                            normalCount++;
                        }
                        logs.Add(StringUtility.Contact(logs.Count, "\t", assetPath, "\t", count, "\t", triangles));
                        meshCount++;
                    }
                }
                index++;
                EditorUtility.DisplayProgressBar("检查Mesh文件", StringUtility.Contact("检查资源文件:", asset.name, "(", index, "/", total, ")"), (float)index / total);
            }
            Debug.LogFormat("检查Mesh文件结束,共检查{0}个Mesh文件,其中{1}个文件正常,{2}个文件疑似异常", meshCount, normalCount, errorCount);
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
        finally
        {
            File.WriteAllLines(Application.dataPath + "/FbxCheckResult.txt", logs.ToArray());
            EditorUtility.ClearProgressBar();
        }
    public static void LoadMesh()
    {
        var assets = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
        var total = assets.Length;
        var index = 0;
        var meshCount = 0;
        var normalCount = 0;
        var errorCount = 0;
        logs.Clear();
        logs.Add(StringUtility.Contact("序号", "\t", "资源名", "\t", "顶点数", "\t", "三角面"));
        try
        {
            foreach (var asset in assets)
            {
                var assetPath = AssetDatabase.GetAssetPath(asset);
                if (!assetPath.Contains("@"))
                {
                    var mesh = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Mesh));
                    if (mesh != null)
                    {
                        var count = ((Mesh)mesh).vertices.Length;
                        var triangles = ((Mesh)mesh).triangles.Length / 3;
                        var countStandard = 2500;
                        var trianglesStandard = 2600;
                        if (mesh.name.Contains("M") || mesh.name.Contains("N"))
                        {
                            countStandard = 2000;
                            trianglesStandard = 2000;
                        }
                        if (count > countStandard || triangles > trianglesStandard)
                        {
                            Debug.LogErrorFormat("{0}文件-->:顶点数:{1},三角面数:{2}", assetPath, count, triangles);
                            errorCount++;
                        }
                        else
                        {
                            Debug.LogFormat("{0}文件-->:顶点数:{1},三角面数:{2}", assetPath, count, triangles);
                            normalCount++;
                        }
                        logs.Add(StringUtility.Contact(logs.Count, "\t", assetPath, "\t", count, "\t", triangles));
                        meshCount++;
                    }
                }
                index++;
                EditorUtility.DisplayProgressBar("检查Mesh文件", StringUtility.Contact("检查资源文件:", asset.name, "(", index, "/", total, ")"), (float)index / total);
            }
            Debug.LogFormat("检查Mesh文件结束,共检查{0}个Mesh文件,其中{1}个文件正常,{2}个文件疑似异常", meshCount, normalCount, errorCount);
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
        finally
        {
            File.WriteAllLines(Application.dataPath + "/FbxCheckResult.txt", logs.ToArray());
            EditorUtility.ClearProgressBar();
        }
    }
}