孫廣東 2015.9.28
C# 6.0 新增的 特性包括: http://blog.csdn.net/u010019717/article/details/46379447
當(dāng)然可以了!
Unity使用的結(jié)構(gòu) CLR 2.0 已有很長的時間,但幾乎所有最新的 C# 功能 不需要最新版本的 CLR。微軟和Mono編譯器可以為 CLR 2.0 編譯 C# 6.0 代碼。
C# 4.0 附帶的 后期綁定 (dynamic) 功能仍不可以在Unity中使用,因?yàn)樗蕾囉?CLR 4.0,我們還沒有。
好吧,該怎么辦?
1. 將這個庫中的 smcs\smcs\bin\Release\smcs.exe 復(fù)制到 \Unity\Editor\Data\Mono\lib\mono\2.0 文件夾中。只是復(fù)制,沒什么可替換。
2. 創(chuàng)建一個新的Unity項(xiàng)目 或 打開一個現(xiàn)有。請確保將Project Settings/Player
/API Compatibility Level
( 兼容級別)設(shè)置為.Net 2.0。
3. 將 mcs.exe 或 Roslyn 文件夾復(fù)制到您的項(xiàng)目根。
就是這樣。
它是如何工作的?
smcs.exe 接收 和 重定向編譯請求從Unity到一個可用 C# 編譯器使用下列規(guī)則:
1. 如果當(dāng)前項(xiàng)目中包含 Roslyn 文件夾,然后將使用 Roslyn C# 6.0 編譯器;
2. 否則如果 如果當(dāng)前項(xiàng)目中包含 mcs.exe,然后將使用此Mono C# 6.0 編譯器;
3. 否則如果在項(xiàng)目內(nèi)部的某個地方有 AsyncBridge.Net35.dll (多線程相關(guān)),然后Unity的 5.0 C# 編譯器會被使用 (\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.5\mcs.exe);
4. 否則 存儲 編譯器將使用 (\Unity\Editor\Data\Mono\lib\mono\2.0\gmcs.exe)。
It means that Unity will use the alternative compiler only in those projects, where you have explicitely expressed your wish to do so. Otherwise, it will use the stock compiler as usual, and the only bad thing that can happen is if smcs.exe crashes for whatever reason instead of doing its job. Then you can just delete it and continue as if nothing ever happened.
它意味著Unity 將使用另一種編譯器只有在這些項(xiàng)目中,在那里你有明確表示你希望這樣做。否則它會使用存儲編譯器像往常一樣,唯一不好的事情是,如果 smcs.exe 崩潰不管出于什么原因而不是做它的工作。然后你就可以刪除它然后繼續(xù)仿佛什么都不曾發(fā)生。
需求:
http://forum.unity3d.com/threads/c-6-0.314297/
http://forum.unity3d.com/threads/free-trial-unity-c-6-0-compiler.314800/
解決:
https://bitbucket.org/alexzzzz/unity-c-5.0-and-6.0-integration/src