[Unity基础]unity调用dll文件以及反射加载dll
来源:互联网 发布:phpcms建站 编辑:程序博客网 时间:2024/05/18 01:04
参考链接:
http://liweizhaolili.blog.163.com/blog/static/1623074420144313825921/
http://blog.csdn.net/janeky/article/details/25923151
http://m.blog.csdn.net/blog/ordinary0214/20935321
一、调用dll文件中的c#类
a.新建项目,选择类库,选择.NET Framework 2.0
b.
using System;using System.Collections.Generic;using System.Text;public class CSharpDll{ public static int Add(int a, int b) { return a + b; }}
c.菜单栏,生成 / 生成解决方案,生成的dll文件会出现在bin\Debug下,然后把它复制到Assets目录下
d.
using UnityEngine;using System.Collections;public class TestDll : MonoBehaviour {void Start () { print(CSharpDll.Add(1, 2));}}
二、调用dll文件中的MonoBehaviour类
a.新建项目,选择类库,选择.NET Framework 2.0
b.菜单栏,项目,添加引用,unity安装目录\Editor\Data\Managed,找到UnityEngine.dll直接添加(即项目/添加引用,脚本中使用的命名空间来自哪些dll,就引用哪些dll)
using UnityEngine;using System.Collections;public class MonoDll : MonoBehaviour { void Start() { print("Start"); } void Update() { print("Update"); } public void PrintInfo() { print("Hello"); }}
c.菜单栏,生成 / 生成解决方案,生成的dll文件会出现在bin\Debug下,然后把它复制到Assets目录下
d.
using UnityEngine;using System.Collections;public class TestMonoDll : MonoBehaviour {// Use this for initializationvoid Start () { MonoDll m = gameObject.AddComponent<MonoDll>(); m.PrintInfo();}}
反射就是得到程序集中的属性和方法
a.将导入的.dll文件改后缀为.bytes
b.打包上面的文件,可以参考:http://blog.csdn.net/lyh916/article/details/46289407
c.
using UnityEngine;using System.Collections;using System.Reflection;using System;public class TestDll : MonoBehaviour { private static readonly string path = "file://" + Application.dataPath + "/StreamingAssets/" + "ALL.assetbundle"; void Start() { StartCoroutine(loadDllScript()); } IEnumerator loadDllScript() { WWW www = WWW.LoadFromCacheOrDownload(path, 10); yield return www; AssetBundle bundle = www.assetBundle; TextAsset asset = bundle.Load("ClassLibrary1", typeof(TextAsset)) as TextAsset; Assembly assembly = Assembly.Load(asset.bytes); Type t = assembly.GetType("CSharpDll"); MethodInfo method = t.GetMethod("Add"); System.Object[] p = new System.Object[] { 1, 2 }; print(method.Invoke(t,p)); TextAsset asset2 = bundle.Load("ClassLibrary2", typeof(TextAsset)) as TextAsset; Assembly assembly2 = Assembly.Load(asset2.bytes); Type t2 = assembly2.GetType("MonoDll"); gameObject.AddComponent(t2); } }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
dll反编译:
使用工具:Reflector
下载地址:http://pan.baidu.com/s/1kTJDyyb
在vs菜单栏,项目/添加引用
dll混淆:
http://liweizhaolili.blog.163.com/blog/static/1623074420145110502776/
dll热更新:
http://www.cnblogs.com/plateFace/p/4790437.html
- [Unity基础]unity调用dll文件以及反射加载dll
- Unity 动态加载dll
- unity中调用dll
- unity调用dll注意
- Unity调用DLL
- unity调用dll注意
- unity调用c++ dll
- unity中调用dll文件总结
- Unity调用C++中DLL文件
- Unity 调用外部DLL插件
- Unity调用C++的Dll文件,Xcode的.a文件
- unity 加载c++ dll文件提示DllNotFoundException的解决办法
- unity引用dll文件方法
- unity引用dll文件方法
- 制作和unity调用动态链接库dll文件
- 制作和unity调用动态链接库dll文件
- Dll的编写 在unity中加载
- unity加载dll库的学习笔记
- git@osc中协作开发、复制项目、贡献代码
- android中json解析的两个工具:Gson和Jackson的使用小demo
- x264命令行参数解释
- MTK 双卡切单卡配置(项目积累)
- 项目实战:OTA系统升级
- [Unity基础]unity调用dll文件以及反射加载dll
- 总结整理时下流行的浏览器User-Agent大全
- LeetCode: Repeated DNA Sequences
- 黑马程序员-Java学习笔记之异常和包
- linux yum 安装svn
- 死锁的必要条件和解决方法
- leetCode #191 number of 1 bits
- 开篇记(2015.03.10)
- APP中注册时常用的发送验证码的Button,带倒计时重发功能