Class ReferenceImageOptimizer
The ReferenceImageOptimizer class is responsible for optimizing reference images in Unity projects. It allows you to filter images, compare them, and remove duplicates. It uses a texture comparison algorithm to determine the similarity between images and can move images to a base folder for better organization. The optimizer runs asynchronously and provides progress updates and statistics about the optimization process. It also provides events to notify when statistics are gathered and when the optimization is complete.
Implements
Inherited Members
Namespace: UnityEditor.TestTools.Graphics
Assembly: UnityEditor.TestTools.Graphics.dll
Syntax
public sealed class ReferenceImageOptimizer : IDisposable
Properties
Status
Status of the optimization process.
Declaration
public OptimizationStatus Status { get; }
Property Value
| Type | Description |
|---|---|
| OptimizationStatus |
Methods
Dispose()
Declaration
public void Dispose()
OptimizeReferenceImages(string, int)
Starts the optimization process for reference images with a specified filter and maximum concurrency. This method allows you to specify a filter to match against the reference image names and the maximum number of concurrent tasks to run during the optimization. The optimization will run asynchronously, and the progress will be shown in the editor.
Declaration
public static void OptimizeReferenceImages(string filter, int maxConcurrency)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filter | The filter to match against reference image names. This can be a regular expression that will be used to filter the reference images. For example, to match all images for a specific test, you can use "TestName". If you want to match all images, you can pass an empty string. |
| int | maxConcurrency | The maximum number of concurrent tasks to run during the optimization. This allows you to control how many images are processed at the same time. A higher value may speed up the optimization process, but it may also increase memory usage and CPU load, so it should be set according to your system's capabilities. The default value is 8, which is a good balance for most systems. |
Events
OnOptimizationComplete
Event that is invoked when the optimization process has completed. This event provides the final optimization result, including elapsed time, total comparisons, deleted files, moved files, and the status of the optimization.
Declaration
public static event EventHandler<OptimizationResult> OnOptimizationComplete
Event Type
| Type | Description |
|---|---|
| EventHandler<OptimizationResult> |
OnStatsReceived
Event that is invoked when the optimizer has gathered statistics for a set of images. This event provides the test name and metrics for the images, such as platform count and accumulated divergence.
Declaration
public static event EventHandler<ImageStatsEventArgs> OnStatsReceived
Event Type
| Type | Description |
|---|---|
| EventHandler<ImageStatsEventArgs> |