using UnityEngine; using System.Collections; using UnityEditor; using System.Collections.Generic; using System.IO; /// <summary> /// 统计工程内的代码行数 /// </summary> public class CodeCounter { [MenuItem("Tools/统计工程内的代码行数")] public static void Func() { int allRow = 0; string directoryPath = Application.dataPath + "/Script"; Debug.Log("搜索的文件夹:" + directoryPath); List<string> listFiles = new List<string>(Directory.GetFiles(directoryPath, "*.cs", SearchOption.AllDirectories)); Debug.Log("查找到的 C# 文件数量为 " + listFiles.Count); for (int i = 0; i < listFiles.Count; i++) { allRow += File.ReadAllLines(listFiles[i]).Length; } Debug.Log("统计结果:您已经写了 " + allRow + " 行代码。"); } }