Unity:PlayMode UnityTest和EditMode UnityTest有什么区别? [英] Unity: What's the difference between a PlayMode UnityTest and an EditMode UnityTest?

查看:748
本文介绍了Unity:PlayMode UnityTest和EditMode UnityTest有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习如何在Unity3D中编写测试,但文档很少

I'm trying to learn how to write tests in Unity3D, but the documentation is sparse.

您可以在PlayMode或EditMode测试中都使用[UnityTest],但是我不了解选择其中一项的重要性.我认为在PlayMode中,它实际上可以运行您的游戏,但我仍然不明白为什么我会或不想这样做.

You can use [UnityTest] on both PlayMode or EditMode tests, but I don't understand the significance in choosing one over the other. I think in PlayMode, it actually runs your game, but I still don't understand why I would or would not want that.

推荐答案

实际上很简单:

检查不需要播放模式的任何内容(UpdateAwakeStart等),或者必须在输入之前进行显式测试.例如

Check anything that doesn't require PlayMode (Update, Awake, Start etc) or that has to be tested explicitly before entering it. E.g.

  • 场景中是否有Camera?
  • 用于混合现实:播放模式开始之前,相机是否位于位置0, 0, 0?
  • 相机是否具有PhysicsRaycaster组件以使IPointerXxx界面正常工作
  • is there a Camera in the Scene?
  • for mixed reality: is the Camera at position 0, 0, 0 before the playmode starts?
  • does the Camera have a PhysicsRaycaster component to make IPointerXxx interfaces work

对于某些游戏,在进入PlayMode之前必须对其进行测试,而对于其他方法,该方法只是速度更快,因为它无需在场景中初始化所有内容即可测试一项特定的内容

For some it is necessary to test them before entering PlayMode, for the rest this method is simply faster since it doesn't have to initialize everything in your Scene before being able to test one specific thing.

检查需要运行时的脚本(UpdateFixedUpdate等),已初始化的所有内容(已执行AwakeStart等)或物理操作,例如

Check scripts that require runtime (Update, FixedUpdate, etc), everything initialized (executed Awake, Start, etc) or physics e.g.

  • 此对象是否将在访问它们之前初始化所有组件?
  • while循环会在给定时间内终止吗?
  • 我看到的最好的物理示例是有关物理材料的:如果将蹦蹦跳跳"设置为0.99,球会在X秒后停止跳动吗?
  • will this object have all components initialized before accessing them?
  • will this while loop terminate (within a given time)?
  • the best physics example I saw was about Physics materials: If bounciness is set to 0.99 will the ball stop jumping after X seconds?

这篇关于Unity:PlayMode UnityTest和EditMode UnityTest有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆