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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月18日 08时24分42秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
省市区三级联动插件Distpicker--前端实现地区三级联动
2019-04-30
solr的使用详解
2019-04-30
Myslq连接(JDBC)url属性的参数的设置
2019-04-30
关于Java继承,重载及运行的顺序的总结
2019-04-30
关于Spring MVC与前端的交互
2019-04-30
Mybatis逆向工程的使用
2019-04-30
关于Hibernate的优缺点
2019-04-30
常用的 Maven 命令
2019-04-30
常用的20个正则表达式
2019-04-30
数据结构之顺序表的实现
2019-04-30
数据结构之线性链表
2019-04-30
JQuery使用validate插件完成校验
2019-04-30
关于java的继承
2019-04-30
关于java的内部类
2019-04-30
关于java的枚举
2019-04-30
一个简单的layui登陆界面
2019-04-30
SQL考试常见题目
2019-04-30
使用Spring Boot写一个简单的Hello World
2019-04-30
Spring Boot整合Servlet使用
2019-04-30
SpringBoot 文件上传
2019-04-30