【发布时间】:2020-12-02 09:33:28
【问题描述】:
我需要使用 EditorSceneManager 加载场景以进行播放模式单元测试。 我需要使用这个而不是 SceneManager.Load,因为我无法在构建设置中拥有场景。关于 EditorSceneManager 的文档很清楚它应该做我需要的。
protected void LoadScene(string sceneName, Action onComplete)
{
if (string.IsNullOrEmpty(sceneName)) { Debug.LogError("Missing scene name"); return;}
UnityEditor.SceneManagement.EditorSceneManager.LoadScene(sceneName);
//...
}
我收到错误消息,场景不在构建设置中,好像调用了 SceneManager.LoadScene 而不是编辑器版本。
编译器还建议简化为我不想使用的以下内容:
UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);
虽然我没有可能混淆代码的指令:
using System;
using System.Collections;
using UnityEditor;
using UnityEngine;
我使用带有 IPrebuildSetup、IPostBuildCleanup 的辅助解决方案通过 AssetDatabase 和 EditorBuildSettingsScene 添加/删除场景,它可以工作。但它还在构建产品应用程序时在 Jenkins 中运行场景加载/卸载过程。我需要避免这种情况,因为它可能会导致只在测试场景中使用的资产。
【问题讨论】:
标签: c# unit-testing unity3d editor scene