Unity中获取整个项目的代码行数总和
发布日期:2021-06-30 19:57:14 浏览次数:2 分类:技术文章

本文共 1531 字,大约阅读时间需要 5 分钟。

一:使用Directory.GetFiles

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));    }}​

二:使用AssetDatabase.FindAssets

using System;using System.IO;using UnityEditor;using UnityEngine;public class StatisticLine {    [MenuItem("输出总代码行数/输出")]    private static void PrintTotalLine()    {        string[] fileName = AssetDatabase.FindAssets("t:Script", new string[] { "Assets/Scripts" });        int totalLine = 0;        foreach (var temp in fileName)        {            int nowLine = 0;            string path = AssetDatabase.GUIDToAssetPath(temp);            StreamReader sr = new StreamReader(path);            while (sr.ReadLine() != null)            {                nowLine++;            }            //文件名+文件行数            //Debug.Log(String.Format("{0}——{1}", path, nowLine));            totalLine += nowLine;        }        //Debug.Log(String.Format("总代码行数:{0}", totalLine));    }}

 

转载地址:https://liuhaowen.blog.csdn.net/article/details/104288456 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Unity中获取离线时间
下一篇:Unity中实现大数单位转换问题

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月18日 08时24分42秒