How to create DLLs for Unity?

I guess the first question is Why? Why create DLLs?

DLLs can be used to Tidy Up Unity Code, speed up compile time (a bit)makes it easier to redistribute code and a bunch of other Pros (but also Cons), and reduce deployment clutter and you can literally put everything you need – textures, audio, whatever – inside one file.

Okay, so now, How? Unity actually has a pretty good tutorial on How, but it lacks pictures and fails to mention some quirks.

Let’s get started:

  1. Create a New Solution in MonoDevelop, select C# > Library.
  2. Specify its Name, Location and Solution Name. 
  3. Reference Unity DLLs, by going to Project > Edit References…
  4. Select .Net Assembly, and navigate to: /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll, and click Add. 
  5. UnityEngine.dll will then be included in the References folder of the Solution.
  6. Add files by right clicking on the solution and Add > Add Files…
  7. Before building, make sure that Mono Soft Debugger Support for Unity is disabled. Go to MonoDevelop-Unity > Add-in Manager… Unity > Mono Soft Debugger Support for Unity, and click Disable.

    Remember to Enable Mono Soft Debugger Support for Unity again, after building.

  8. Also, make sure Target framework is set to .NET 2.0. Right click on the solution, go to Options > Build > General, and set Target framework.
  9. Click Build > Build All or Build > Build <Solution Name>.
  10. The DLL will be saved in the bin/Debug folder of the Solution.
  11. Copy the DLL file to Assets/Plugins and reference it like any normal script.

There will always be a few Quirks:

  1. Cyclic dependencies of DLL not allowed
  2. Can only reference other DLLs
  3. DLLs cannot be edited in Unity
  4. DLL with dependencies will log error, if dependency not included in Unity Project
  5. DLL scripts cannot be in separate folders (Editor scripts need to be in Editor folder -> build separate DLLs for Editor and normal scripts, use Unity Package to sort them into proper folders)
  6. Change #if UNITY_IPHONE script to if(Application.platform == RuntimePlatform.IPhonePlayer) and change #if UNITY_ANDROID script to if(Application.platform == RuntimePlatform.Android)
  7. Editor Scripts not working properly -> needs to create a proxy script to bind to Unity (http://forum.unity3d.com/threads/editor-script-dll-and-regular-script-dll-not-adding-custominspector-scripts.107720/)
  8. DLL with reference to AndroidJavaObject fails to build for iOS

Some quirks which I can’t seem to resolve and I’m hoping someone can help me:

Advertisements

Review: iPhone JavaScript Cookbook

iPhone JavaScript Cookbook

https://www.packtpub.com/sites/default/files/imagecache/productview/1086EXP_iPhone%20JavaScript%20Development%20Cookbook_cov.jpg

This book is written by Arturo Fernandez Montoro.

This book is written for web dev guys, I guess, who wants to write native looking web applications for the iPhone. The book introduces a lot of frameworks to make life easier. the frameworks include native looking assets for user interface building, which you can call with just a line of code. This book also teaches the readers how to work with data using from SQL and AJAX.

Since this is a cookbook, it includes a lot of recipes that readers can copy and paste and revise.

If you want to make applications for the iPhone that look like applications for the iPhone, without having to learn Objective C, the iPhone SDK and all, then this book is a great guide for you. 🙂  

Link: http://www.packtpub.com/iphone-javascript-cookbook/book/mid/170811hge054

iPhone JavaScript Cookbook

iPhone JavaScript Cookbook

Overview of iPhone JavaScript Cookbook

  • Build web applications for iPhone with a native look feel using only JavaScript, CSS, and XHTML
  • Develop applications faster using frameworks
  • Integrate videos, sound, and images into your iPhone applications
  • Work with data using SQL and AJAX
  • Write code to integrate your own applications with famous websites such as Facebook, Twitter, and Flickr
  • These practical recipes include code and screenshots offering a clear step-by-step guide using different frameworks
  • eBook available as PDF and ePub downloads.

Link: http://www.packtpub.com/iphone-javascript-cookbook/book