文档

Unity 引擎

Unity 引擎

测试条件编译

代码示例和测试条件编译代码的步骤。
阅读时间1 分钟最后更新于 5 天前

以下示例展示了如何测试按条件编译的代码。它还根据为 Target 版本选定的平台打印 message。

代码示例

using UnityEngine;using System.Collections;public class PlatformDefines :MonoBehaviour {void Start () { #if UNITY_EDITOR Debug.Log("Unity Editor"); #endif #if UNITY_IOS Debug.Log("Unity iOS"); #endif #if UNITY_STANDALONE_OSX Debug.Log("Standalone OSX"); #endif #if UNITY_STANDALONE_WIN Debug.Log("Standalone Windows"); #endif} }

测试说明

  1. Open the Build Profiles 窗口(菜单:文件 > 生成配置文件)。
  2. Check要测试代码的平台是ON Active 平台配置文件文件。如果不是,请选择首选平台,然后单击 切换配置文件。
  3. 创建脚本并复制和粘贴样本代码。
  4. 在 Game View 工具栏中,单击播放按钮进入播放模式。Confirm 通过检查与 Unity 控制台中选定的平台相关的消息来确认代码是否正常工作。例如,如果选择 iOS,消息
    Unity Editor
    和
    Unity iOS
    将显示在控制台中。

其他资源