Git Product home page Git Product logo

unityengineanalyzer's Introduction

UnityEngineAnalyzer

UnityEngineAnalyzer is a set of Roslyn analyzers that aim to detect common problems in Unity3D C# code. Unity3D makes it easy for us to make cross platform games, but there are hidden rules about performance and AOT, which might only come with experience, testing or reading the forums. It is hoped that such problems can be caught before compilation.

Comand Line Interface

In order to use the Command Line Interface (CLI), download the latest release of UnityEngineAnalyzer then unzip the archive.

  1. Open a Command Prompt or Powershell Window
  2. Run UnityEngineAnalyzer.CLI.exe <project path>
  3. Observe the analysis results
  4. (Optional) In the same location as the project file are report.json and UnityReport.html files containig the results of the analysis

Example:

> UnityEngineAnalyzer.CLI.exe C:\Code\MyGame.CSharp.csproj

Visual Studio Integration

In Visual Studio 2015, go to Tools > Nuget Package Manager > Manage Nuget Packages for Solution.... Search for and install UnityEngineAnalyzer

Configuration

Right-click Analyzers to modify the severity or to disable the rule completely.

Limitations

  • HTML Report requires FireFox or XOR (Corss Origin Request) enabled in other browsers
  • It doesn't have rules for all of Mono's AOT Limitations
  • IL2CPP might change the limitations of AOT compilation

Below is a sample of all the rules available in this analyzer

// AOT0001: System.Runtime.Remoting is not suppported
using System.Runtime.Remoting;
// AOT0002: System.Reflection.Emit is not supported
using System.Reflection.Emit;
using UnityEngine;

class FooBehaviour : MonoBehaviour 
{
	void Start()
	{
		// AOT0003: Reflection only works for looking up existing types
		Type.GetType("");

		// UEA0002: Using string methods can lead to code that is hard to maintain
		SendMessage("");

		// UEA0006: Use of coroutines cause some allocations
		StartCoroutine("");
	}

	// UEA0001: Using OnGUI causes allocations and GC spikes
	void OnGUI()
	{

	}

	// UEA0003: Empty MonoBehaviour methods are executed and incur a small overhead
	void FixedUpdate()
	{

	}

	void OnTriggerEnter(Collider other)
	{
		// UEA0004: Using CompareTag for tag comparison does not cause allocations
		if (other.tag == "")
		{

		}
	}

	void Update()
	{
		// UEA0005: Warning to cache the result of find in Start or Awake
		GameObject.Find("");
	}
}

License

See LICENSE

unityengineanalyzer's People

Contributors

vad710 avatar meng-hui avatar

Watchers

James Cloos avatar

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.