浏览代码

Secure data in test result window

/main
Remy 7 年前
当前提交
fe85f0a8
共有 1 个文件被更改,包括 85 次插入41 次删除
  1. 126
      Tests/Scripts/Editor/GraphicTests/Framework/TestResultWindow.cs

126
Tests/Scripts/Editor/GraphicTests/Framework/TestResultWindow.cs


{
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)
private void Reload(string name)
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);
}
else
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 (diffMaterial == null)
{
diffMaterial = new Material(Shader.Find("GraphicTests/ComparerShader"));
diffMaterial.hideFlags = HideFlags.HideAndDontSave;
DontDestroyOnLoad(diffMaterial);
}
}
private void Reload(SceneAsset _sceneAsset = null)
{
sceneAsset = _sceneAsset;
if (sceneAsset == null) return;
if (templateImage != null && templateImage != Texture2D.whiteTexture) DestroyImmediate(templateImage);
tmpPath = "";
GetTemplateImage();
string templatePath = Path.Combine( TestFrameworkTools.s_RootPath, "ImageTemplates");
templateLocation = Path.Combine(templatePath, string.Format("{0}.{1}", tmpPath, "png"));
GetDiffMaterial();
// Search for fail image if it exists.
GetResultImage();
ApplyValues();
testResultTreeView.Reload();
}

DestroyImmediate(templateImage);
if(resultImage != null && resultImage != Texture2D.blackTexture) DestroyImmediate(resultImage);
if (templateImage != null && templateImage != Texture2D.whiteTexture) DestroyImmediate(templateImage);
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);
diffMaterial.SetFloat("_CorrectGamma", 1f);
diffMaterial.SetFloat("_FlipV2", 0f);
}
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.SaveCurrentModifiedScenesIfUserWantsTo();
EditorSceneManager.OpenScene(AssetDatabase.GetAssetPath(FindScene(FindItem(id, rootItem).displayName)), OpenSceneMode.Single);
}
}

正在加载...
取消
保存