日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

dll放在unity哪个文件夹下_unity中调用dll文件总结

發布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 dll放在unity哪个文件夹下_unity中调用dll文件总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

unity中調用dll文件總結

根據收集的資料,對unity中調用dll文件進行總結,目前常用的兩種,在給出vs中封裝dll文件的步驟。

一、調用c#中的dll文件

1.1封裝dll文件

首先新建一個項目

然后創建一個類庫,例如命名為Csharp

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Csharp

{

public class Class1

{

public static string getName(string name)

{

return name;

}

}

} 然后編譯成dll文件,名字為Csharp.dll

1.2.在unity中使用自定義的dll組件

在unity中創建一個Plugins文件夾,所有的外部引用的dll組件必須要放在這個文件下,才能被using。如果是C#封裝的dll,就用 using的方式引用,如果是C++的dll,就DllImport[""]的方式來添加對dll的引用。然后我在C#腳本中用這個dllusing UnityEngine;

using System.Collections;

using Csharp; //引用c#生成的dll文件,namespace的名字

public class TestDllOne : MonoBehaviour {

// Use this for initialization

void Start () {

}

// Update is called once per frame

void OnGUI()

{

if (GUILayout.Button("test c# dll"))

{

Debug.Log(Class1.getName("hello world "));

}

}

二、調用c++中的dll文件

在本文中用VS2013進行 C++創建DLL圖解

1.創建項目: Win32->Win32項目,名稱:MyDll

.

單擊下一步后選擇如下圖所示

單擊完成后,右擊選擇頭文件-->添加 ----> 新建項如下圖操作

選擇頭文件并且命名,例如TestDll.h,命名后單擊添加

在TestDll.h 頭文件中寫入代碼如下# define _DLLExport __declspec (dllexport)

# else

# define _DLLExport __declspec (dllimport)

#endif

extern "C" int _DLLExport MyADD(int x, int y);

選擇源文件,如下圖所示

``

選擇添加后,在Test.cpp 源文件中寫入代碼如下//宏定義

#define EXPORTBUILD

//加載頭文件

#include "TestDll.h"

//設置函數

int _DLLExport MyADD(int x, int y)

{

return x + y;

}

編譯后將生成的MyDll.dll 文件導入unity中的Plugins文件中

如果是C++的dll,就DllImport[""]的方式來添加對dll的引用using UnityEngine;

using System.Collections;

using System.Runtime.InteropServices; //調用c++中dll文件需要引入

public class TestDllOne : MonoBehaviour {

[DllImport("MyDll")]

static extern int MyADD(int x , int y);

// Use this for initialization

void Start () {

}

// Update is called once per frame

void OnGUI()

{

if (GUILayout.Button("test c++ dll"))

{

int i = MyADD(12 , 23);

Debug.Log("sum = :" + i.ToString());

}

}

}

使用c#生產的dll會有如下問題:

Running into Issues?:

Internal compiler error ... System.Reflection.ReflectionTypeLoadException

If you are getting an error similar to Internal compiler error. System.Reflection.ReflectionTypeLoadException in Unity when trying to build your project; You need to change the targeted .NET version of your C# file to something like .NET 3.5.Right click on your C# project and go to Properties

In the Application tab, change the Target Framework to .NET Framework 3.5

Failed to load ... expected 64 bit architecture (IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386.

If you are getting this error, you probably need to recompile your libraries for x64 platform (64 bit).

In Visual Studio, go to the properties of your project, then at the top click the "Configuration Manager..." button. In the table, under the Platform column, change it to "x64" then recompile your project.

作者:我聽到你了

ps:以上是unity中調用dll文件總結全部內容,希望文章能夠幫你解決unity中調用dll文件總結所遇到的游戲開發問題。

本文收錄在 游戲編程 🕹? - 學習Unity專題,分享走一走~

總結

以上是生活随笔為你收集整理的dll放在unity哪个文件夹下_unity中调用dll文件总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。