LoginSignup
3
1

More than 5 years have passed since last update.

Unityプロジェクト内にある、すべてのC#スクリプトのステップ数をカウントするEditor拡張

Posted at

今関わっているUnityプロジェクトのスクリプトって全部でどれくらいのステップ数あるのかなと思い、計算している人を探したのですが、見当たらなかったので自作しました。Editor拡張になります。
コードは以下です。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Linq;

public class CountLine : EditorWindow {

    [MenuItem("Window/LineCount")]
    public static void Init()
    {
        CountLine window = EditorWindow.GetWindow<CountLine>("CountLine");
        window.Show();
        window.Focus();
    }

    private void OnGUI()
    { 
        if (GUILayout.Button("Count All Script line"))
        {
            DirectoryInfo dir = new DirectoryInfo(Application.dataPath);
            FileInfo[] info = dir.GetFiles("*.cs", System.IO.SearchOption.AllDirectories);
            if(info == null || info.Length == 0)
            {
                return;
            }

            int allLineCount = 0;
            info.Where((x) => x.Name != "CountLine.cs").ToList().ForEach((x) => {

                using (StreamReader sr = x.OpenText())
                {
                    while(sr.ReadLine() != null)
                    {
                        allLineCount++;
                    }
                }
            });

            Debug.LogFormat("Number of All Scripts line is {0}", allLineCount);

        }
    }
}

自身のスクリプトはカウントしていないようにしています。
こちらのスクリプトを、適当なEditorフォルダにつっこんでもらって、Windowタブ->LineCountを開き、「Count All Script line」というボタンを押せば計算が始まります。結果はコンソールに出力されます。
ささっと作ったものなので、もし不具合ある場合は教えていただけると幸いです。。

3
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1