浏览代码

Move auto bake for TestRunner from HDRP to the test framework.

Add context menu option for scenes to toggle the needed asset label and apply necessary settings (manual lightmap bake, .gitignore for lightmapping data).
/main
Remy 7 年前
当前提交
e15aef56
共有 6 个文件被更改,包括 106 次插入45 次删除
  1. 42
      TestProjects/HDRP_Tests/Assets/GraphicTests/Common/TestRunner/HDRP_GraphicTestRunner.cs
  2. 2
      TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2101_GI_Metapass.unity.meta
  3. 2
      TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2102_GI_Emission.unity.meta
  4. 2
      TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2103_BakeMixed.unity.meta
  5. 2
      TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2601_ColorTemp.unity.meta
  6. 101
      com.unity.testframework.graphics/Editor/SetupGraphicsTestCases.cs

42
TestProjects/HDRP_Tests/Assets/GraphicTests/Common/TestRunner/HDRP_GraphicTestRunner.cs


using UnityEngine.SceneManagement;
using UnityEngine.Events;
#if UNITY_EDITOR
using UnityEditor;
using EditorSceneManagement = UnityEditor.SceneManagement;
#endif
public class HDRP_GraphicTestRunner : IPrebuildSetup
public class HDRP_GraphicTestRunner
{
[UnityTest, Category("HDRP Graphic Tests")]
[PrebuildSetup("SetupGraphicsTestCases")]

yield return null;
ImageAssert.AreEqual(testCase.ReferenceImage, camera, (settings != null)?settings.ImageComparisonSettings:null);
}
public void Setup()
{
#if UNITY_EDITOR
// For each scene in the build settings, force build of the lightmaps if it has "DoLightmap" label.
// Note that in the PreBuildSetup stage, TestRunner has already created a new scene with its testing monobehaviours
Scene trScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(0);
foreach( EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
{
SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath<SceneAsset>(scene.path);
var labels = new System.Collections.Generic.List<string>(AssetDatabase.GetLabels(sceneAsset));
if ( labels.Contains("DoLightmap") )
{
EditorSceneManagement.EditorSceneManager.OpenScene(scene.path, EditorSceneManagement.OpenSceneMode.Additive);
Scene currentScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(1);
EditorSceneManagement.EditorSceneManager.SetActiveScene(currentScene);
Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
Lightmapping.Bake();
EditorSceneManagement.EditorSceneManager.SaveScene( currentScene );
EditorSceneManagement.EditorSceneManager.SetActiveScene(trScene);
EditorSceneManagement.EditorSceneManager.CloseScene(currentScene, true);
}
}
#endif
}
#if UNITY_EDITOR

2
TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2101_GI_Metapass.unity.meta


fileFormatVersion: 2
guid: 8747b43f8bcf2b44cbc3ece373da65a9
labels:
- DoLightmap
- TestRunnerBake
DefaultImporter:
externalObjects: {}
userData:

2
TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2102_GI_Emission.unity.meta


fileFormatVersion: 2
guid: b8f49ca9a12abb4468116e9422139e63
labels:
- DoLightmap
- TestRunnerBake
DefaultImporter:
externalObjects: {}
userData:

2
TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2103_BakeMixed.unity.meta


fileFormatVersion: 2
guid: d8cfa4fd9319d2444b3bf6dd836ffe31
labels:
- DoLightmap
- TestRunnerBake
DefaultImporter:
externalObjects: {}
userData:

2
TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2601_ColorTemp.unity.meta


fileFormatVersion: 2
guid: 34a3a4a7a56d3014dad3114e6b523742
labels:
- DoLightmap
- TestRunnerBake
DefaultImporter:
externalObjects: {}
userData:

101
com.unity.testframework.graphics/Editor/SetupGraphicsTestCases.cs


using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.TestTools;
using UnityEngine.SceneManagement;
using UnityEditor;
using EditorSceneManagement = UnityEditor.SceneManagement;
namespace UnityEditor.TestTools.Graphics
{

/// Will also build Lightmaps for specially labelled scenes.
static string bakeLabel = "TestRunnerBake";
private static bool IsBuildingForEditorPlaymode
{
get

}
}
// For each scene in the build settings, force build of the lightmaps if it has "DoLightmap" label.
// Note that in the PreBuildSetup stage, TestRunner has already created a new scene with its testing monobehaviours
Scene trScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(0);
foreach( EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
{
SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath<SceneAsset>(scene.path);
var labels = new System.Collections.Generic.List<string>(AssetDatabase.GetLabels(sceneAsset));
if ( labels.Contains(bakeLabel) )
{
EditorSceneManagement.EditorSceneManager.OpenScene(scene.path, EditorSceneManagement.OpenSceneMode.Additive);
Scene currentScene = EditorSceneManagement.EditorSceneManager.GetSceneAt(1);
EditorSceneManagement.EditorSceneManager.SetActiveScene(currentScene);
Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
Lightmapping.Bake();
EditorSceneManagement.EditorSceneManager.SaveScene( currentScene );
EditorSceneManagement.EditorSceneManager.SetActiveScene(trScene);
EditorSceneManagement.EditorSceneManager.CloseScene(currentScene, true);
}
}
}
static string lightmapDataGitIgnore = @"Lightmap-*_comp*
LightingData.*
ReflectionProbe-*";
[MenuItem("Assets/Tests/Toggle Scene for Bake")]
public static void LabelSceneForBake()
{
UnityEngine.Object[] sceneAssets = Selection.GetFiltered(typeof(SceneAsset), SelectionMode.DeepAssets);
EditorSceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
EditorSceneManagement.SceneSetup[] previousSceneSetup = EditorSceneManagement.EditorSceneManager.GetSceneManagerSetup();
foreach (UnityEngine.Object sceneAsset in sceneAssets)
{
List<string> labels = new System.Collections.Generic.List<string>(AssetDatabase.GetLabels(sceneAsset));
string scenePath = AssetDatabase.GetAssetPath(sceneAsset);
string gitIgnorePath = Path.Combine( Path.Combine( Application.dataPath.Substring(0, Application.dataPath.Length-6), scenePath.Substring(0, scenePath.Length-6) ) , ".gitignore" );
if (labels.Contains(bakeLabel))
{
labels.Remove(bakeLabel);
File.Delete(gitIgnorePath);
}
else
{
labels.Add(bakeLabel);
string sceneLightingDataFolder = Path.Combine( Path.GetDirectoryName(scenePath), Path.GetFileNameWithoutExtension(scenePath) );
if ( !AssetDatabase.IsValidFolder(sceneLightingDataFolder) )
AssetDatabase.CreateFolder( Path.GetDirectoryName(scenePath), Path.GetFileNameWithoutExtension(scenePath) );
File.WriteAllText(gitIgnorePath, lightmapDataGitIgnore);
EditorSceneManagement.EditorSceneManager.OpenScene(scenePath, EditorSceneManagement.OpenSceneMode.Single);
EditorSceneManagement.EditorSceneManager.SetActiveScene( EditorSceneManagement.EditorSceneManager.GetSceneAt(0) );
Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
EditorSceneManagement.EditorSceneManager.SaveScene( EditorSceneManagement.EditorSceneManager.GetSceneAt(0) );
}
AssetDatabase.SetLabels( sceneAsset, labels.ToArray() );
}
AssetDatabase.Refresh();
if (previousSceneSetup.Length == 0)
EditorSceneManagement.EditorSceneManager.NewScene(EditorSceneManagement.NewSceneSetup.DefaultGameObjects, EditorSceneManagement.NewSceneMode.Single);
else
EditorSceneManagement.EditorSceneManager.RestoreSceneManagerSetup(previousSceneSetup);
}
[MenuItem("Assets/Tests/Toggle Scene for Bake", true)]
public static bool LabelSceneForBake_Test()
{
return IsSceneAssetSelected();
}
public static bool IsSceneAssetSelected()
{
UnityEngine.Object[] sceneAssets = Selection.GetFiltered(typeof(SceneAsset), SelectionMode.DeepAssets);
return sceneAssets.Length != 0;
}
}
}
正在加载...
取消
保存