Unity3D 如何调用DLL

本文详细介绍了如何在C#中通过DllImport调用Win32 API函数,并提供了实例演示如何将DLL文件整合到Unity项目中,以及如何在C#脚本中调用插件函数。

 

 

转载请著名出处:http://oulehui.blog.163.com/blog/static/79614698201011835819382/
JS用法
import System;
import System.Runtime.InteropServices;
@DllImport("user32.dll")
public static function MessageBox(Hwnd : int,text : String,Caption : String,iType : int) : int {};

function Start()
{
MessageBox(0, "API Message Box", "Win32 API", 64) ;
}
function Update () {
}


补充C#用法

C文件
float FooPluginFunction () { return 5.0F; }
将DLL放在 Assets->Plugins文件夹中,文件夹自己建立

C#脚本
using UnityEngine;
using System.Runtime.InteropServices;

class SomeScript : MonoBehaviour {
   // This tells unity to look up the function FooPluginFunction
   // inside the plugin named "PluginName"
   [DllImport ("PluginName")]
   private static extern float FooPluginFunction ();

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

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值