Tuesday, December 15, 2009

C# 3.0 in Unity3D?

Yes, it seems it is possible.

From http://answers.unity3d.com/:

Download and install the latest version of Mono (2.4.3)

From C:\Program Files\Mono-2.4.2.3\bin, grab these files: mono.exe, mono.dll, libglib-2.0-0.dll, libgmodule-2.0-0.dll

From C:\Program Files\Mono-2.4.2.3\lib\mono\2.0, grab these files: gmcs.exe, gmcs.exe.config, mscorlib.dll

Copy all these files to Unity\Editor\Data\MonoCompiler.framework

I'm guessing that this works because the C# 3.0 compiler still compiles to bytecode which is compatible with the mono runtime used by Unity 2.6.

I might try this out later, and post instructions for OSX.

3 comments:

Lucas said...

Hey. You can do this, and it works a bit, however, you can only use c# features that are "compiler syntactical sugar"

like collection initializers, and type inference (var a = 4;)

Note that you also pay. The produced mdb files are no longer compatible, which means that you'll lose line numbers in your stacktraces, which is actually very annoying.

I used it for a while, and decided it was not worth it after a while, since the amount of c# features you actually get are not that many.

Scott Mitting said...

Lucas is absolutely correct, 3.0 and 3.5 required no bytecode changes to the CLR.

I've been enjoying running MonoDevelop with the .sln solutions generated by Unity 2.6, then outputting the DLLs to the assets folder. This lets me use unit tests and debugging!

One note when doing this though, you can't instantiate MonoBehaviour from a console app... I created a work around using #if directives to create code compatible for both environments. I'll post the code if anyone is interested.

I guess I've been tasked with creating a blog starting next month to advertise for our unityessentials.com add-ons. I think I just decided one of my topics.

rahul said...

First of all. Thanks very much for your useful post.

I just came across your blog and wanted to drop you a note telling you how impressed I was with the

information you have posted here.

Please let me introduce you some info related to this post and I hope that it is useful for community.

There is a good C# resource site, Have alook

http://CSharpTalk.com

Thanks again
Rahul

Popular Posts