Unity中获取整个项目的代码行数总和
发布日期:2021-06-30 19:57:14
浏览次数:3
分类:技术文章
本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月12日 22时50分49秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
数据结构期末复习------查找汇总
2019-04-30
Vue学习(10)————————编程式导航,地址栏的#号去掉,路由的嵌套
2019-04-30
SpringBoot内置Tomcat配置参数
2019-04-30
Nginx基本知识
2019-04-30
微服务公用实体类andLombok
2019-04-30
小问题
2019-04-30
Spring Security之旅————————————基本介绍安装(1)
2019-04-30
Spring IO Platform学习
2019-04-30
局部加权回归
2019-04-30
已知后序和中序求层序
2019-04-30
1051. Pop Sequence (25)
2019-04-30
ELK系列:新版ELK安装(windows与linux环境)
2019-04-30
Discovering Neural Wiring(2019 nips, nas)
2019-04-30
2020kickstart E round C Toys (优先队列)
2019-04-30
pytorch raise NotImplementedError
2021-07-03
LeetCode 887. 鸡蛋掉落
2021-07-03
第七届acm省赛总结
2021-07-03
oj第一次打字比赛成绩
2021-07-03