Write a Unity Editor window test
To test UI rendering and custom Unity Editor windows, write a test that captures the Unity Editor interface.
For more information about using a test after you write it, refer to Run a graphics test for the first time and Run a test and check the results.
Capture an Editor window
To capture an Editor window as a texture, use the EditorWindowCapture.CaptureAsync API. Follow these steps:
Create an
EditorWindowobject with the window you want to capture. For example:EditorWindow window = EditorWindow.CreateWindow<SceneView>();Create capture settings using
EditorWindowCaptureSettings. For example:EditorWindowCaptureSettings settings = new EditorWindowCaptureSettings( width: 1024, height: 768, delayBeforeCapture: TimeSpan.FromSeconds(0.5) );Note: You can use
EditorWindowCaptureSettings.Defaultfor a default 512 × 512 capture with no delay.Use the
EditorWindowCapture.CaptureAsyncAPI to capture the window. For example:Texture2D capture = await EditorWindowCapture.CaptureAsync(window, settings);
You can also pass in actions to the window before you capture it using a (window) setup action. For example the following changes the window title:
EditorWindowCaptureSettings settings = new EditorWindowCaptureSettings(
...
(window) => { window.titleContent = new GUIContent("Test Window"); }
)
For more information, refer to Asynchronous tests.
Capture the Scene view
If you capture the Scene view window, you can use a SceneViewCaptureSettings object instead of an EditorWindowCaptureSettings object, and set two additional settings:
ImageComparisonViewpoint: Sets the Scene view camera transform before capture to ensure a consistent viewpoint.Timeout: Sets a timeout for async operations such as shader compilation, to avoid indefinite waits.
You can use SceneViewCaptureSettings.Default to create settings for a standard Scene view capture.