使用Unity2018 的TestRunner,无法引用自己的代码进行测试,原因是测试代码和程序代码不在同一个程序集,无法引用;需要新建程序集,进行引用。

Script compilation and assembly definition files

About

Unity automatically defines how scripts
 compile to managed assemblies. Typically, compilation times in the Unity Editor for iterative script changes increase as you add more scripts to the Project.

Use an assembly definition file to define your own managed assemblies based upon scripts inside a folder. To do this, separate Project scripts into multiple assemblies with well-defined dependencies in order to ensure that only required assemblies are rebuilt when making changes in a script. This reduces compilation time. Think of each managed assembly as a single library within the Unity Project.

Figure 1 - Script compilation

Figure 1 above illustrates how to split the Project scripts into several assemblies. Changing only scripts in Main.dll causes none of the other assemblies to recompile. Since Main.dll contains fewer scripts, it also compiles faster than Assembly-CSharp.dll. Similarly, script changes in only Stuff.dll causes Main.dll and Stuff.dll to recompile.

How to use assembly definition files

Assembly definition files are Asset files that you create by going to Assets
 > Create > Assembly Definition. They have the extension .asmdef.

Add an assembly definition file to a folder in a Unity Project to compile all the scripts in the folder into an assembly. Set the name of the assembly in the Inspector
.

Note: The name of the folder in which the assembly definition file resides and the filename of the assembly definition file have no effect on the name of the assembly.

Figure 2 - Example Import Settings

Add references to other assembly definition files in the Project using the Inspector too. To view the Inspector, click your Assembly Definition file and it should appear. To add a reference, click the + icon under the References section and choose your file.

Unity uses the references to compile the assemblies and also defines the dependencies between the assemblies.

To mark the assembly for testing, enable Test Assemblies in the Inspector. This adds references to unit.framework.dll and UnityEngine.TestRunner.dll in the Assembly Definition file.

When you mark an assembly for testing, makes sure that:

  • Predefined assemblies (Assembly-CSharp.dll etc.) do not automatically reference Assembly Definition Files flagged for testing.

  • The assembly is not included in a normal build. To include the assemblies in a player build, use BuildOptions.IncludeTestAssemblies in your building script. Note that this only includes the assemblies in your build and does not execute any tests.

Note: If you use the unsafe keyword in a script inside an assembly, you must enable the Allow ‘unsafe’ Code option in the Inspector. This will pass the /unsafe option to the C# compiler when compiling the assembly.

https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html

Predefined assemblies:

Unity compiles scripts
 in four separate phases, based on where the script file is located within the project folder structure. Unity creates a separate CSharp project file (.csproj) and a predefined assembly for each phase. (If there are no scripts eligible for a compilation phase, Unity does not create the corresponding project file or assembly.)

Compilation order is significant when a script references a class compiled in a different phase (and therefore located in a different assembly). The basic rule is that anything that is compiled in a phase after the current one cannot be referenced. Anything that is compiled in the current phase or an earlier phase is fully available.

https://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html

Unity Predefined assemblies/assembly definition files相关推荐

  1. [洪流学堂]Unity2017.3新功能:程序集定义(Assembly Definition File)功能详解

    本文首发于"洪流学堂"公众号. 洪流学堂,让你快人几步 Unity2017.3已经发布,其中一大新功能是:程序集定义文件(Assembly Definition File),下面文 ...

  2. 程序集定义(Assembly Definition File)

    unity导入dll 报错:Assembly 'Assets/Plugins/xxx.dll' will not be loaded due to errors: Unable to resolve ...

  3. About Site Definition Files

    在SDK里看到的,转一个,备忘一下. 转载于:https://www.cnblogs.com/RockingEgg/archive/2009/02/19/1393896.html

  4. Unity 2017.3 Beta已发布

    Have you ever considered being a beta tester? You'll get early access to the latest new features, an ...

  5. Hands-On Unity 2018 x 移动游戏开发教程

    Hands-On Unity 2018 x Game Development for Mobile 使用Unity 2018.2创建具有出色游戏功能的精彩游戏 想学习在Unity制作游戏,但不知道从哪 ...

  6. Unity 托管内存(Managed Memory)

    翻译:https://unity3d.com/cn/learn/tutorials/topics/best-practices/managed-memory 理解托管堆对 Unity 中的内存管理至关 ...

  7. Assembly definitions 的相关实验

    概述 大概从 Unity 2017.3 开始,添加了 assembly definition 相关的功能.为了更深入的了解,进行了多次打包和对比.本文主要是对这一过程进行记录. 文档解释 1.编译脚本 ...

  8. 【翻译】Unity2017.3 版本发布说明

    文章目录 简介 编辑器与引擎 支持Mono NET 2 的内存分析器( Memory Profiler) 变换工具 (Transform Tool) 图像 (Graphics) 原文作者为: Carl ...

  9. Unity关于程序集(Assembly )的那些事

    学习大纲 一. 什么是程序集? 二. 为什么使用程序集? 三. 如何在Unity中使用程序集 1.基本常识 2.自定义程序集 3. 多层级的程序集 4. Assembly Definition Ref ...

最新文章

  1. 微信小程序实时将less编译为wxss
  2. 机器学习基础-集成学习-13
  3. Web---JSP-EL表达式
  4. PostgreSQL增强版命令行客户端(pgcli)
  5. MySQL Mac安装教程
  6. 字节跳动被爆商业化部门大量裁员
  7. mysql学习笔记03 mysql数据类型
  8. 露天影院网站_为什么要在露天工作?
  9. FPN网络详解——feature pyramid network
  10. cad巧用插件自定义填充图形
  11. 2013大数据全球技术峰会PPT
  12. 安卓调用科大讯飞语音
  13. 网盘变成本地硬盘教程
  14. 什么是DNS over HTTPS?
  15. jquery ZeroClipboard实现黏贴板功能,兼容所有浏览器
  16. Angular 入门教程系列:37:使用ng-alain快速开发
  17. 企业CDN缓存加速原理
  18. 马尔科夫不等式和坎泰利不等式的证明
  19. 备份恢复 --已整理
  20. O2O优惠券发放与使用情况分析

热门文章

  1. php缓存远程图片接口,Android_Android远程获取图片并本地缓存,对于客户端——服务器端应用 - phpStudy...
  2. python中 and 和 or 操作的返回值。
  3. !include: could not find: nsProcess.nsh
  4. 数据结构学习(考研408)
  5. angular 获取上一个路由地址 获取当前页地址 地址裁切
  6. hdu 4215 Number Theory?(打表)
  7. “广告分佣+社交电商”:消费全返积分的电商模式
  8. kafka reassign 限速_车主无忧:为什么放弃开源Kafka?
  9. 扫码签到突破100000用户
  10. 【金猿投融展】易观数科——智能用户运营服务商