欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

调用Native Plugin

程序员文章站 2022-03-23 21:31:43
使用C/C++生成的库,调用方法如下 // Native Plugin 中声明的函数 float FooPluginFunction () { return 5.0F; }...

使用C/C++生成的库,调用方法如下

// Native Plugin 中声明的函数
float FooPluginFunction () { return 5.0F; } 
using UnityEngine;
    using System.Runtime.InteropServices;

    class SomeScript : MonoBehaviour {

       #if UNITY_IPHONE

       // On iOS plugins are statically linked into
       // the executable, so we have to use __Internal as the
       // library name.
       [DllImport ("__Internal")]

       #else

       // Other platforms load plugins dynamically, so pass the name
       // of the plugin's dynamic library.
       [DllImport ("PluginName")]

       #endif

       private static extern float FooPluginFunction ();

       void Awake () {
          // Calls the FooPluginFunction inside the plugin
          // And prints 5 to the console
          print (FooPluginFunction ());
       }
    }