Unity中获取整个项目的代码行数总和

将代码放在Editor文件夹下即可

using System;
using System.IO;
using UnityEngine;
using UnityEditor;

public class StatisticLine
{
    [MenuItem("输出总代码行数/输出")]
    private static void PrintTotalLine()
    {
        string[] fileName = Directory.GetFiles("Assets/Scripts", "*.cs", SearchOption.AllDirectories);

        int totalLine = 0;
        foreach (var temp in fileName)
        {
            int nowLine = 0;
            StreamReader sr = new StreamReader(temp);
            while (sr.ReadLine() != null)
            {
                nowLine++;
            }

            //文件名+文件行数
            //Debug.Log(String.Format("{0}——{1}", temp, nowLine));

            totalLine += nowLine;
        }

        Debug.Log(String.Format("总代码行数:{0}", totalLine));
    }
}

​
发布了138 篇原创文章 · 获赞 292 · 访问量 27万+

猜你喜欢

转载自blog.csdn.net/LLLLL__/article/details/104288456