关于mono dll和native dll在unity使用

关于mono dll和native dll在unity中的使用

在使用mono的dll文件时,先利用VS2015生成dll(C#源代码),然后在unity的C#脚本中使用,使用方法如下:

例如C#代码源文件如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpDllTest
{
    public class Class1
    {
        public static int sum(int a, int b)
        {
            return a + b;
        }
    }
}

然后会在工程目录的bin/debug/目录下生成对应dll文件

同理C/C++的动态库也如此

我们在unity中某个脚本上使用上述dll文件中的接口,代码如下

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;

public class TestDll : MonoBehaviour {

    [DllImport("CppDLL", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Add")]
    private extern static int CppAdd(int a, int b);

	// Use this for initialization
	void Start () {
        Debug.Log("CSharp Dll");
        Debug.Log("1 + 1 = " + CSharpDLL.TestDLL.Add(1, 1));

        Debug.Log("Cpp Dll");
        Debug.Log("1 + 1 = " + CppAdd(1, 1));
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值