MonoDevelop offers a great but often unnoticed feature for decompiling C# libraries: The Assembly Browser.
The Assembly Browser decompiles managed code and displays it in your MonoDevelop IDE.
Think of plugins from the Unity Asset Store or other third-party modules: Many tools come as a pre-compiled package, such as Dynamic Link Library (.DLL). While you can import and use these libraries easily in Unity, you can’t just open their files and look at the scripts underneath, or can you?
Let’s take a look under the hood of Unity and disassemble one of MonoBehaviour’s methods:
public class Test : MonoBehaviour
void Start ()
//Calculate which number is halfway between 0 and 100
float lerpValue = Mathf.Lerp(0f, 100f, 0.5f);
- Copy the code to a new C# script in Unity and open it in MonoDevelop.
- Place the text cursor within the method name Lerp and right-click Go to declaration or hit Cmd/Ctrl + Y.
When inspecting a MonoBehaviour method, this will take us to the Assembly Browser, since all Unity functions are part of our current Assembly.
You’re not allowed to alter Unity methods directly, but via the Assembly Browser you can take a look at many implementations.
Inspecting the disassembled Mathf.Lerp(), you can see exactly how it works. This comes in handy when deciding on which implementation is the right for your project; sometimes the Unity MonoBehaviour methods might not be what you want.
Note, that the Assembly Browser only shows managed code.
In short: Managed code in Unity = C#
Managed code in Unity means C# and Java. These programming languages are easily decompiled by MonoDevelop, native code like C or C++, however, is not.
Since most of Unity’s inner workings are written in C++ or use other highly-optimized machine language libraries, there are many MonoBehaviour methods, which you can’t disassemble to their roots in MonoDevelop. Still, most of the time, the Assemble Browser will show you enough information to let you guess what is going on.
Here’s another example:
Most functions from the Mathf or Vector3 class show us how they work in the Assembly Browser. I encourage you to occasionally look at the implementation of such methods when using them in your project. It can be incredibly helpful to understand the math behind these helpers, because one day you might want to use custom implementations that fit your needs exactly.
Browsing through pre-compiled plugins from the Asset Store is just as simple as looking at MonoBehaviour methods:
- Open a Unity project and import a plugin.
- Open the project (Solution) in MonoDevelop by opening any script from the Unity editor or clicking Assets > Sync MonoDevelop Project.
- In MonoDevelop go to View > Solution to show the solution browser.
- A third-party plugin will show under References. Double click the file to open it in the Assembly Browser. Or just open View > Assembly Browser and find the plugin there.
- Make sure to set Visibility to All members, or else you will only see public variables.
- Methods and properties can usually be found in a main class with the same name as the plugin. (Look for the “C” on blue background icon to find classes.)
Use MonoDevelop’s Assembly Browser to decompile any managed library or plugin and learn from real-world examples!
Thank you for reading! I hope you found this quick tip inspiring.