Unity3d Plugin in Windows and Linux

Recently, I need to write Unity3d plugin. My partner develops Unity3d Project in Windows system, but whole project needs to run in Linux system. This article will show you how to include Unity3d plugin under Windows and Linux.

First of all, you need to know that extension of Unity3d plugin is different in Windows and Linux. For example, we want to create a “cleanwind” plugin, in Windows it’s “cleanwind.dll“, but in Linux it’s “libcleanwind.so“.Here point is, the prefix “lib” must exist in Linux and not show in Windows.

Unity3d supports C# and Javascript, they have same object, property, and method. PLEASE DO NOT believe any unconfirmed rumors. The difference between C# and Javascript in Unity3d is just syntax.

We assumed plugin “cleanwind” has “hello()” and “world()” functions  :
  int hello() {
    return 1;
  }
int world() {
    return 2;
  }

Includes Unity3d plugin using C# :
  using System.Runtime.InteropServices;
  [DllImport (“cleanwind”)]
private static extern int world ();
  [DllImport (“cleanwind”)]
private static extern int hello ();

Includes Unity3d plugin using Javascript :
  import System.Runtime.InteropServices;
  @DllImport (“cleanwind”)
  private static function hello () : int {} ;
@DllImport (“cleanwind”)
  private static function world () : int {} ;

Now you can use “hello()” and “world()” functions in your project both in Windows and Linux system. If you have any problems or find any wrong in this article, please don’t feel shy to contact me.

Reference : Unity – Manual: Plugins (Pro/Mobile-Only Feature)
http://docs.unity3d.com/Manual/Plugins.html

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

數學難題 * 限制時效已用盡。請重新載入驗證碼。