Unity封装dll教程整理

来源:互联网 发布:c语言字符串格式化 编辑:程序博客网 时间:2024/06/08 00:04

///作者Unity3d师兄---LeroyYang

通过网上大神们的资料以及自己的整理,学习一下用vs2013简单的封装dll文件,方便接口模式下开发,使得逻辑层更为清晰。

操作步骤

1、打开vs2013,新建项目 -新建类库 (注意最上面.NET Framework选择3.5版本以下的,因为Unity3D(当前的Unity3D版本是3.5版) 支持的 .Net 是3.5版。 如果选择的是4.0版会出现 Internal compiler error. See the console log for more information. output was:Unhandled Exception: System.TypeLoadException: Could not load type 'System.Runtime.Versioning. 错误。   )

2、项目新建完成之后,编写简单的测试代码

using System;

namespace yanglei {

public class Yl

{

public static int Attack(int hp)

{

return hp;

}

}

}

3、生成解决方案,找到vs项目工程文件夹目录在E:\ProjectYang\bin\Debug下的dll文件

4、导入dll到Unity中,在Unity中Asset文件夹下新建文件夹名为Plugins目录

5、在Unity新建脚本

using UnityEngine;

using System.Collections;

using yanglei;

public class actionscript : MonoBehaviour {

void Start () {

int hp = Yl.Attack(100);

Debug.Log(hp);

}

}

运行结果

1 0
原创粉丝点击