This is a .NET tool that analyzes Unity projects. This tool scans Unity scenes and scripts to identify unused C# MonoBehaviour scripts and generates structured dumps of your scene hierarchies. It does this by analyzing the files in parallel and uses the Roslyn API to parse C# files.
git clone git@github.com:Harry-258/unity-analysis-tool.git
cd unity-analysis-toolFrom the root directory
cd UnityAnalysisTool
dotnet run <path-to-unity-project> <path-to-output-directory>Example:
cd UnityAnalysisTool
dotnet run "C:\Projects\MyUnityGame" "C:\AnalysisOutput"From the root directory
cd UnityAnalysisTool.Tests
dotnet testThe tool assumes that all .cs files inside the project are directly inherited from MonoBehaviour and ignores the prefab system. It does not use any Unity API and works without running the Unity Editor.
This project was done over the course of 2 days as part of a challenge. With more time, these are the improvements that could be made:
- Optimize the tool by using more efficient data structures. This could allow the tool to run constantly in the background of an IDE. Some solutions may inlcude using binary trees to keep track of hierarchies.
- Add support for other types of scripts, such as those inheriting from ScriptableObject.
- Write more tests. Besides unit tests, I would try to use property-based testing to test the properties behind parsing files and writing to dump or csv files. Also, Integration tests should be present.