Unity3d中C#使用指针(Unsafe)的办法
来源:互联网 发布:麦克格雷迪生涯数据 编辑:程序博客网 时间:2024/09/21 06:38
Unity3d中C#使用指针(Unsafe)的办法
近日由于在U3D项目中要使用到数据传递(C++ DLL的数据传递给U3D中的C#),其中涉及到需要使用C#的指针。直接编译会出现以下错误Unsafe code requires the 'unsafe' command line option to be specified。
下面是我总结的解决办法:
1.去除MONO编辑器中的Unsafe错误,Assembly-CSharp鼠标右键 找到Options->Build->General 。Allow 'unsafe' code 打钩。这个只能去除MONO报错,但是依然无法运行。
2.首先看下面一段比较长的
Custom Preprocessor Directives
It is also possible to define your own preprocessor directives to control which code gets included when compiling. To do this you must add in the "Assets/" folder a text file with the extra directives. The name of the file depends on the language you are using :
C#<Project Path>/Assets/smcs.rspC# - Editor Scripts<Project Path>/Assets/gmcs.rspUnityScript<Project Path>/Assets/us.rspBoo<Project Path>/Assets/boo.rspAs an example, if you include the single line '-define:UNITY_DEBUG' in your smcs.rsp file the define UNITY_DEBUG will exist as a global define for C# scripts, except for Editor scripts.
Every time you make make changes to the .rsp files a recompilation needs to be done for them to be effective. You can do this by updating or reimporting a single script (.js, .cs or .boo) file.
The usage of the .rsp files is described in the help of the smcs application, included in the Editor installation folder. You can get more information by running : "smcs -help".
在你的Assets目录下面添加smcs.rsp文件,里面只加一行字不要有空格 -unsafe。 OK搞定。记得一定要重启Unity3d, 因为这个预编译是在启动U3D时候运行的。工程文件名别带中文。
原理是编辑器中的smcs.exe 添加编译命令,也可以在CMD下运行编辑器目录下的smcs.exe 逐个添加,会很累的。
测试代码:
unsafe void test () {
int i=10;
int k;
int *j=&i;
k=*j+1;
print("unsafe test " + k.ToString());
}
由www.J2meGame.com原创,转载请说明。
- Unity3d中C#使用指针(Unsafe)的办法
- Unity3d中C#使用指针(Unsafe)的办法 宏 预处理
- Unity3D中C#使用指针(Unsafe)报错处理
- C#中指针*的使用(unsafe关键字与fixed 语句)
- (转)C#中使用指针转换数据类型[C#/unsafe]
- C#中unsafe的使用
- C#中unsafe的使用
- C#中unsafe的使用
- c#指针(unsafe与fixed的使用)
- c#指针(unsafe与fixed的使用)
- C#中使用指针转换数据类型[C#/unsafe]
- C#中指针*的使用(unsafe关键字与fixed 语句)---01
- C#中指针*的使用(unsafe关键字与fixed 语句)---01
- C# 托管代码 和 unsafe使用指针 对数组操作 性能比较--指针真的快么?
- C#指针- unsafe与fixed
- C#指针- unsafe与fixed
- C#指针- unsafe与fixed
- c# 指针unsafe/fixed -- 【一】
- 技术书籍及网站
- 条件变量
- poj 3130 How I Mathematician Wonder What You Are! - 求多边形有没有核 - 模版
- perl系统变量
- 【discuzX2】模板中添加DIY扩拖拽区域
- Unity3d中C#使用指针(Unsafe)的办法
- 4.0后,home键的捕获~
- Maven vs Ant 思维导图
- Excel---实现鼠触图片显示
- JVM Management API
- 练习:js无刷新评论
- hadoop shell 命令
- 怎么写一个温泉管理系统
- 当你途经我的盛放--一无所有的幸福