A lightweight yet extensible Unity Editor tool for analyzing your codebase using Lines of Code (LOC) metrics. It helps you quickly identify large scripts, monitor code growth, and support refactoring decisions.
-
🔍 Scan
.csfiles in your project -
📁 Configurable:
- Include folders
- Ignore folders
-
📊 In-editor visualization:
- File-level LOC
- Total LOC
- Largest file detection
-
🔽 Sorting:
- By line count (asc/desc)
- By file path
-
📌 Ping file in Project window
-
💾 Export report to
.txt -
📥 Import report from
.txt -
🔁 Reusable data (no re-scan needed for sorting/filtering)
When working on medium-to-large Unity projects, it becomes difficult to:
- Identify overly large scripts
- Track codebase growth
- Decide where to refactor
This tool provides a quick structural overview of your codebase using LOC as a simple but effective metric.
- Copy file into your project:
Assets/Editor/LOCGeneratorWindow.cs
-
Open Unity
-
Access tool via menu:
Tools → LOC Generator
-
Include Folders
- Where to scan (e.g.
Assets/Scripts)
- Where to scan (e.g.
-
Ignore Folders
- Exclude paths (e.g.
Assets/Thirdparties,Assets/Plugins)
- Exclude paths (e.g.
Click:
Generate
This will:
- Scan all
.csfiles - Calculate LOC per file
- Display results in the window
Use dropdown:
Sort By:
- LinesDesc
- LinesAsc
- Path
Click:
Export File
Output example:
Assets/Scripts/MyScript.cs - 120 lines
Assets/Scripts/Player.cs - 340 lines
...
Total lines of code: 7842
Click:
Import File
-
Load previously exported
.txt -
Rebuild full dataset inside tool
-
Useful for:
- Sharing between team members
- Comparing snapshots
The tool expects this format:
<file_path> - <line_count> lines
...
Total lines of code: <total>
The tool is structured for extensibility:
Scans project and builds data
LOCGenerator.Generate(...)
Parses existing report file
LOCImporter.ImportFromFile(...)
Writes report to file
LOCExporter.ExportToFile(...)
Handles:
- UI
- Sorting
- User interaction
- 🔎 Detect God Classes (>300–500 LOC)
- 🧱 Identify refactor targets
- 📈 Track project growth over time
- 🧪 Compare code size between branches (manual)
- 👨💻 Support code reviews
-
LOC ≠ code quality
-
Does not measure:
- Complexity (Cyclomatic)
- Maintainability index
-
Counts physical lines, not logical statements
If you plan to extend this tool:
- LOC Diff (compare 2 reports)
- Highlight large files (color UI)
- Group by folder
- CSV / JSON export
- Incremental scan (file hash / timestamp)
- Code complexity metrics
- Integration with CI pipeline
From a report like this:
- 700+ LOC file → candidate for splitting
- Folder with 60% LOC → architectural hotspot
- Sudden LOC increase → possible feature spike or tech debt
You can extend this tool by:
- Adding new exporters
- Improving parsing logic
- Enhancing UI/UX
- Adding analytics features
Use freely for personal or internal team projects.
Unity, Editor Tool, LOC, Code Metrics, Refactoring, Code Analysis
