加外链网站,外贸圈名人堂,中国建设业管理协会网站,外链工具xg下载unity中调用dll文件总结根据收集的资料#xff0c;对unity中调用dll文件进行总结#xff0c;目前常用的两种#xff0c;在给出vs中封装dll文件的步骤。一、调用c#中的dll文件1.1封装dll文件首先新建一个项目然后创建一个类库#xff0c;例如命名为Csharpusing System;using…unity中调用dll文件总结根据收集的资料对unity中调用dll文件进行总结目前常用的两种在给出vs中封装dll文件的步骤。一、调用c#中的dll文件1.1封装dll文件首先新建一个项目然后创建一个类库例如命名为Csharpusing 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.dll1.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 initializationvoid Start () {}// Update is called once per framevoid 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)#endifextern 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 initializationvoid Start () {}// Update is called once per framevoid 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.ReflectionTypeLoadExceptionIf 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 PropertiesIn the Application tab, change the Target Framework to .NET Framework 3.5Failed 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专题分享走一走~