{
private Texture2D templateImage;
private Texture2D resultImage;
private GUIContent diffContent;
private string tmpPath;
private Material diffMaterial;
private float minDiff = 0.45f;
private GUIContent wipeResultContent = new GUIContent() {text = "Wipe ⎚", tooltip = "Wipe results."};
private GUIContent deleteTemplateContent = new GUIContent() {text = "Delete 🗑", tooltip = "Delete template."};
private TestResultTreeView testResultTreeView;
private TestResultViewItem testResultViewItem;
// pouet
private TestResultTreeView _testResultTreeView;
private TestResultTreeView testResultTreeView
get
if (_testResultTreeView == null)
_testResultTreeView = new TestResultTreeView(new TreeViewState());
_testResultTreeView.onSceneSelect += Reload;
}
return _testResultTreeView;
[MenuItem("Internal/GraphicTest Tools/Result Window")]
public static void OpenWindow()
TestResultWindow window = GetWindow<TestResultWindow>();
window.minSize = new Vector2(800f, 800f);
window.testResultTreeView = new TestResultTreeView(new TreeViewState());
window.testResultTreeView.onSceneSelect += window.Reload;
private void Reload(string name)
public static SceneAsset FindScene(string name)
string[] guids = AssetDatabase.FindAssets(name.Remove(name.Length-6, 6));
string[] guids = AssetDatabase.FindAssets(name.Remove(name.Length - 6, 6));
Reload();
return null;
else
scene = AssetDatabase.LoadAssetAtPath<SceneAsset>(path);
i++;
Reload(scene);
return scene;
private void Reload(SceneAsset _sceneAsset = null)
sceneAsset = _sceneAsset;
Reload(FindScene(name));
if (sceneAsset == null) return;
private void CheckDataObjects()
if (diffMaterial == null) GetDiffMaterial();
if (templateImage == null) GetTemplateImage();
if (resultImage == null) GetResultImage();
if (templateImage != null) DestroyImmediate(templateImage);
string tmp = "";
private void GetTemplateImage()
templateImage = TestFrameworkTools.GetTemplateImage(sceneAsset, ref tmp);
templateImage = TestFrameworkTools.GetTemplateImage(sceneAsset, ref tmpPath);
string templatePath = Path.Combine( TestFrameworkTools.s_RootPath, "ImageTemplates");
templateLocation = Path.Combine(templatePath, string.Format("{0}.{1}", tmp, "png"));
if (diffContent == null) diffContent = new GUIContent();
diffContent.image = templateImage;
if (diffMaterial == null)
diffMaterial = new Material(Shader.Find("GraphicTests/ComparerShader"));
diffMaterial.hideFlags = HideFlags.HideAndDontSave;
DontDestroyOnLoad(diffMaterial);
diffMaterial.SetFloat("_CorrectGamma", 1f);
diffMaterial.SetFloat("_FlipV2", 0f);
templateImage = Texture2D.whiteTexture;
// Search for fail image if it exists.
private void GetResultImage()
var failedPath = Path.Combine(Directory.GetParent(Application.dataPath).ToString(), "SRP_Failed");
misMatchLocationResult = Path.Combine(failedPath, string.Format("{0}.unity.png", sceneAsset.name));
misMatchLocationTemplate = misMatchLocationResult.Insert(misMatchLocationResult.Length - 10, ".template");
minDiff = 1f;
maxDiff = 1f;
ApplyValues();
private void GetDiffMaterial()
if (templateImage != null && templateImage != Texture2D.whiteTexture) DestroyImmediate(templateImage);
tmpPath = "";
GetTemplateImage();
templateLocation = Path.Combine(templatePath, string.Format("{0}.{1}", tmpPath, "png"));
GetDiffMaterial();
GetResultImage();
testResultTreeView.Reload();
DestroyImmediate(templateImage);
if(resultImage != null && resultImage != Texture2D.blackTexture) DestroyImmediate(resultImage);
if (resultImage != null && resultImage != Texture2D.blackTexture) DestroyImmediate(resultImage);
DestroyImmediate(diffMaterial);
GUI.enabled = true;
if (GUILayout.Button("Open Scene"))
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(sceneAsset), OpenSceneMode.Single);
GUILayout.EndArea();
Rect textureRect = new Rect(leftBarWidth, topBarHeight * 3, position.width - leftBarWidth,
position.height - topBarHeight * 3);
Rect textureRect = new Rect(leftBarWidth, topBarHeight * 3, position.width - leftBarWidth,position.height - topBarHeight * 3);
CheckDataObjects();
EditorGUI.DrawPreviewTexture(textureRect, templateImage, diffMaterial, ScaleMode.ScaleToFit, 0, 0);
diffMaterial.SetFloat("_Split", split);
diffMaterial.SetFloat("_ResultSplit", resultSplit);
diffMaterial.SetInt("_Mode", diffStyle);
public class TestResultTreeView : TreeView
delegate void OnNewSceneSelect(SceneAsset newScene);
public TestResultTreeView(TreeViewState state) : base(state)
//if (testItem!=null) Debug.Log(item.displayName+" : "+testItem.sceneObject);
onSceneSelect(item.displayName);
protected override void DoubleClickedItem(int id)
EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(FindScene(FindItem(id, rootItem).displayName)), OpenSceneMode.Single);