原地址: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);
    }

最新文章

  1. 从A文件拿B文件的某一个值
  2. Linux Runlevel 启动 脚本
  3. IT在线学习网站总结
  4. 为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录
  5. c++引用总结
  6. Eclipse环境下配置spket中ExtJS5.0提示
  7. css sprites-简单实例让你快速掌握css sprites精髓
  8. (function($){...})(jQuery)是什么意思
  9. Python编程指南 chapter 1
  10. 编译及load mydqli.so文件
  11. C++中的运算符优先级
  12. MyBatis,动态传入表名,字段名的解决办法
  13. 开发中关于IPv6的问题
  14. C语言之随机数
  15. 记录自己使用GitHub的点点滴滴
  16. “tar: Removing leading `/’ from member names”的错误
  17. Mysql 5.7 安装 解压缩版 忘记密码
  18. 安卓开发_关于WebView使用链接时调用浏览器显示的问题
  19. centos 7 min 编译安装php5.6+nginx1.7.5 笔记
  20. 调整Linux的最大文件打开数

热门文章

  1. css3动画 bug 2点
  2. [USACO2002][poj1944]Fiber Communications(枚举)
  3. 编写高质量代码改善C#程序的157个建议[协变和逆变]
  4. 第六章:javascript:字典
  5. Webbench网站压力测试
  6. js 选项卡实现
  7. FastDFS在.Net平台上的使用
  8. oracle 用Navicat创建的表的查询问题
  9. BZOJ2120 数颜色
  10. Uva11729 Commando War