Banbury / UnityPsdImporter

Advanced PSD importer for Unity3D
Other
167 stars 65 forks source link

Compile Errors in Unity Editor #9

Closed madclouds closed 9 years ago

madclouds commented 9 years ago

Hey Banbury!

I can't believe how difficult it is to get PSD data into Unity. You'd think they'd build it in natively. I don't want to re-position/layer all the work my designer has already done!

I'm very excited for this plugin! Unfortunately, I can't get it to compile correctly in the Unity Editor. Unity keeps displaying console errors:

Assets/PhotoShopFileType/PsdFile/Layers/Channel.cs(273,25): error CS0227: Unsafe code requires the 'unsafe' command line option to be specified Assets/PhotoShopFileType/PsdFile/Layers/Layer.cs(206,11): error CS0227: Unsafe code requires the 'unsafe' command line option to be specified Assets/PhotoShopFileType/PsdFile/PsdBinaryReader.cs(80,7): error CS0227: Unsafe code requires the 'unsafe' command line option to be specified etc...

I tried to follow your readme.md but I didn't quite understand this paragraph:

To compile the Unity PSD Importer in the Unity3D Editor you must have the files gmcs.rsp and smcs.rsp with "-unsafe" in the first line of the files in the root directory of your project. Otherwise you can compile the code as a DLL and it will also work in the editor.

When I moved gmcs.rsp and smcss.rsp to my projects root directory, it had no effect. Should I be adding the unsafe comment to every .cs file affected?

I should mention I'm on a MacBook Pro running OS X 10.10.2 and Unity 4.6.2f1

Banbury commented 9 years ago

Here's some documentation on how to modify the compile options in Unity: http://docs.unity3d.com/Manual/PlatformDependentCompilation.html

gmcs.rsp and smcs.rsp seem to be used to add additional compiler switches (in this case '-unsafe') to the calls of the C# compiler. Personally I prefer to compile the code as a DLL in a separate solution. Then I copy the DLL to the game folder.

madclouds commented 9 years ago

Thanks for responding so quickly Banbury!

Compiling the code as a DLL and copying it to the game folder does seem like an easier solution. I thought the DLL extension was windows only? Any idea if this will work on a mac too?

May I ask what technique you use to compile the DLL?

madclouds commented 9 years ago

A quick search turned up these resources:

http://docs.unity3d.com/Manual/UsingDLL.html

http://forum.unity3d.com/threads/creatng-windows-usable-dll-in-osx.99348/

I'll see if there's a way to build it using MonoDevelop.

Banbury commented 9 years ago

DLLs in DotNet are different. They are executed on a Virtual Machine. For Unity this is called Mono. And as long as you don't use any features, that Mono doesn't support, you can use DLLs compiled with Micorsoft's .NET compiler. For PSDImporter you have to allow unsafe code. I don't know, how this is done in MonoDevelop, but in Visual Studio this is a switch in the project properties. I'm closing this issue now, because everything else can be found via Google.

madclouds commented 9 years ago

Thanks again for the help on this topic Banbury - and for authoring such a great tool!

For anyone else who may find this thread, I was able to get the Editor plugin working on my mac simply by going to Edit > Project Settings > Player and under the "Other Settings" adding 'unsafe' to the Scripting Define Symbols section:

unsafe