unity3d进行脚本资源打包加载
原地址:http://www.cnblogs.com/hisiqi/p/3204752.html
本文记录如何通过unity3d进行脚本资源打包加载
1、创建TestDll.cs文件
public class TestDll : MonoBehaviour {
void Start () {
print("Hi U_tansuo!");
}
}
2、生成dll文件
(1)使用vs打包
(2) 使用mono打包
(3) 命令行打包 mac下(亲测): /Applications/Unity/Unity.app/Contents/Frameworks/Mono/bin/gmcs -r:/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll -target:library 脚本路径
win下(未试过):mcs -r:/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll -target:library 脚本路径
3、更改文件后缀
至关重要一步 更改上一步生成的TestDLL.dll 为 TestDLL.bytes 否则 打包加载会错
4、使用 BuildPipeline.BuildAssetBundle进行打包 资源为 TestDll.unity3d
5、加载
IEnumerator Test()
{
string url="file://"+Application.dataPath+"/TestDll.unity3d";
print(url);
WWW www = WWW.LoadFromCacheOrDownload (url, 1);
// Wait for download to complete
yield return www;
// Load and retrieve the AssetBundle
AssetBundle bundle = www.assetBundle;
TextAsset txt = bundle.Load("TestDll", typeof(TextAsset)) as TextAsset;
print(txt.bytes.Length);
// Load the assembly and get a type (class) from it
var assembly = System.Reflection.Assembly.Load(txt.bytes);
var type = assembly.GetType("TestDll");
// Instantiate a GameObject and add a component with the loaded class
gameObject.AddComponent(type);
}
最新文章
- 从A文件拿B文件的某一个值
- Linux Runlevel 启动 脚本
- IT在线学习网站总结
- 为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录
- c++引用总结
- Eclipse环境下配置spket中ExtJS5.0提示
- css sprites-简单实例让你快速掌握css sprites精髓
- (function($){...})(jQuery)是什么意思
- Python编程指南 chapter 1
- 编译及load mydqli.so文件
- C++中的运算符优先级
- MyBatis,动态传入表名,字段名的解决办法
- 开发中关于IPv6的问题
- C语言之随机数
- 记录自己使用GitHub的点点滴滴
- “tar: Removing leading `/’ from member names”的错误
- Mysql 5.7 安装 解压缩版 忘记密码
- 安卓开发_关于WebView使用链接时调用浏览器显示的问题
- centos 7 min 编译安装php5.6+nginx1.7.5 笔记
- 调整Linux的最大文件打开数