Code Monkey home page Code Monkey logo

unityrefanalyzer's Introduction

UnityRefAnalizer

Build status NuGet

Roslyn code analyzer to find method usages on scenes. Early stage of production, issues represents progress.

You can see which methods is referenced from scenes: screen_1

And even find objects where it referenced: screen_2

Summary

This project get you ability to track scene references to your methods inside your IDE. It's useful, because IDE don't now anything about such links and you can't rely only on "Find References" feature. Example: you think that method in your class isn't used and decided to remove it. But you identify issues with that only when open one of your scene, when it actually used and inspect references. Such problems is hard to predict in common cases.

UnityRefAnalyzer contains two parts:

  • Unity-side exporter - made .json report about suck links from your assets
  • Roslyn analyzer - analyze report & your sources

Features

  • Shows warnings on methods, which referenced via Inspector (in IDE)
  • Show warnings on missing references in Unity log when exporting data

Requirements

  • Unity 2017.3+
  • Scripting backend: experimental (.NET 4.6+)

Installation

NuGet

Visual Studio

  • Project/Manage NuGet Packages, find UnityRefAnalyzer, install it
  • or Tools/NuGet Package Manager/Package Manager Console, 'Install-Package UnityRefAnalyzer'

Rider

  • Switch to Solution mode in explorer panel
  • Project/Manage NuGet Packages, find UnityRefAnalyzer, install it

Manual

  • Open RefAnalyzer/RefAnalyzer.sln, build it
  • Open you Unity project

Visual Studio

  • References/AddAnalyzer - select RefAnalyzer/RefAnalyzer/Newtonsoft.Json.dll
  • References/AddAnalyzer - select RefAnalyzer/RefAnalyzer/bin/Debug/netstandard1.3/RefAnalyzer.dll

Rider

  • Add references to csproj file manually: <ItemGroup><Analyzer Include=".../Newtonsoft.Json.dll"/><Analyzer Include=".../RefAnalyzer.dll"/></ItemGroup>

Export

To get analyzer to work, you need to collect data from assets in your Unity project.

  • Import package.unitypackage
  • Open Exporter window - Window/RefAnalyzer
  • Click RefreshData
  • When it's done, you get refs.json file in root of your project
  • It represents all inspector-based links in you assets
  • When you build project in IDE (and if analyzer is installed properly), you get warnings in methods definitions, which is used on scenes
  • If links on your scenes changed, you need to refresh it manually

Debugging

Common

  • If you are changed RefAnalyzer.Shared code, you need to run RefAnalyzer/RefAnalyzer.Shared/copy_dlls_to_unity_project.sh to get this changes on Unity side
  • Or you can copy DLL's manually
  • Use RefAnalizer/Export Package to update package.unitypackage after changes in exporter

Visual Studio

  • Open RefAnalyzer/RefAnalyzer.sln, run it
  • Another Visual Studio instance will appear, when you open any other project, analyzer will be added automatically

Rider

  • Add references to other project manually
  • Changes will be applied when you rebuid other project

unityrefanalyzer's People

Contributors

konh avatar wojciech-dabrowski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

unityrefanalyzer's Issues

Summary for v0.0.1

Features short list:

  • Collect info about assigned via Inspector UnityEvent callbacks from scenes - #2
  • Save it to cache file - #2
  • Load it to analyzer - #4
  • Show warnings/hints on methods which is assigned via Inspector - #5
  • Write overview docs about how it import, use & maintain - #6

Fix working on Mac OS + Rider

When it started, we got exception:
Analyzer 'RefAnalyzer.RefAnalyzer' threw an exception of type 'System.IO.FileNotFoundException' with message 'Could not load file or assembly 'Microsoft.CodeAnalysis.Workspaces, Version=2.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.'.
It's related to way how we find refs file, based on solution, which is Visual Studio based. Need to find workaround.

Improve Unity exporter UI

  • Window title
  • Header with short description
  • Async processing
  • Progress reporting with some progress bar

Add exception helper methods

It's annoying to write such code:

if ( string.IsNullOrEmpty(srcPath) ) {
throw new ArgumentException("srcPath");
}

It's utility code, which required to don't spread errors in code deeply. And it need to be much more simple.
I suggest to use ExceptionHelper methods, which get's object, check it in some way (null, empty string) and raise exception from one place.

Fix missing dependecy issue when trying to parse json in analyzer

Currently we get exception on this line:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.'

It's related to external dependency, which isn't copied to analyzer package.
Solution isn't yet found.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.