简体   繁体   English

我可以在 Unity 中使用预处理器指令来区分调试和发布模式吗

[英]Can I use pre processor directives in Unity to differentiate debug and release mode

I want to create a level-based game with Unity.我想用 Unity 创建一个基于关卡的游戏。 Let's assume you unlock the next level after finishing the previous one.让我们假设您在完成上一个级别后解锁下一个级别。 Maybe some levels are locked until you find some items.也许某些级别被锁定,直到您找到一些项目。

How would you test specific parts of your game?您将如何测试游戏的特定部分? Let's say world 3 level 8 contains a part with a cave where the player has to jump over multiple obstacles.假设世界 3 级别 8 包含一个带有洞穴的部分,玩家必须跳过多个障碍物。 How would you test this cave scenario over and over again without restarting the level?您将如何在不重新启动关卡的情况下一遍又一遍地测试这个洞穴场景? I don't mean testing your application with Unit tests.我的意思不是用单元测试来测试你的应用程序。 Maybe you want to try out a specific mechanic and a specific spot in a specific level fits best for your tests.也许您想尝试一个特定的机制,而特定关卡中的特定地点最适合您的测试。

Of course, you could prepare a save game or add some cheat code like "press + to skip this level" but I think the cheat code would be the worst idea because you would have to remove all these lines before releasing your game (and on each next release).当然,您可以准备一个保存游戏或添加一些作弊代码,例如“按 + 跳过此级别”,但我认为作弊代码将是最糟糕的主意,因为您必须在发布游戏之前删除所有这些行(以及每个下一个版本)。

When developing with C# and Visual Studio it's possible to add preprocessor-directives .使用 C# 和 Visual Studio 进行开发时,可以添加预处理器指令 Does something similar exist for game development, especially for Unity?游戏开发是否存在类似的东西,尤其是对于 Unity?

Yes.是的。 You may define them in Scripting Define Symbols , accessible from:您可以在Scripting Define Symbols 中定义它们,可从以下位置访问:

Edit -> Project Settings -> Player -> Other Settings -> Scripting Define Symbols编辑 -> 项目设置 -> 播放器 -> 其他设置 -> 脚本定义符号

From the manual you may also find the most useful directives already implemented in unity.手册中,您还可以找到已经在 unity 中实现的最有用的指令。

They are mostly used for platform dependent compilation, but they can be used also to differentiate between editor and real application.它们主要用于平台相关编译,但它们也可用于区分编辑器和实际应用程序。

For example #if UNITY_EDITOR will run the code just if you're in the unity editor.例如, #if UNITY_EDITOR将在您使用统一编辑器时运行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM