From cfd6e19ff96ef8a57a4ca60f9daa52f045585617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 30 Jun 2020 12:56:24 +0200 Subject: [PATCH 1/2] Fix test scene description asset UI --- .../Editor/Common/TestSceneAssetEditor.cs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/com.unity.testing.graphics-performance/Editor/Common/TestSceneAssetEditor.cs b/com.unity.testing.graphics-performance/Editor/Common/TestSceneAssetEditor.cs index 3a424255a98..a730f01d716 100644 --- a/com.unity.testing.graphics-performance/Editor/Common/TestSceneAssetEditor.cs +++ b/com.unity.testing.graphics-performance/Editor/Common/TestSceneAssetEditor.cs @@ -7,6 +7,7 @@ using System.Linq; using static PerformanceMetricNames; using Object = UnityEngine.Object; +using System.IO; [CustomEditor(typeof(TestSceneAsset))] class TestSceneAssetEditor : Editor @@ -67,12 +68,27 @@ void InitSceneDataReorderableList(ReorderableList list, string title) rect.height = EditorGUIUtility.singleLineHeight; // Scene field - var sceneGUID = AssetDatabase.FindAssets($"t:Scene {sceneName.stringValue}", new [] {"Assets"}).FirstOrDefault(); - var sceneAsset = String.IsNullOrEmpty(sceneGUID) ? null : AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(sceneGUID)); + var sceneGUID = AssetDatabase.FindAssets($"t:Scene {sceneName.stringValue}", new [] {"Assets", "Packages"}).FirstOrDefault(); + SceneAsset sceneAsset = null; + if (!String.IsNullOrEmpty(sceneGUID)) + { + string path = AssetDatabase.GUIDToAssetPath(sceneGUID); + + // Only if the scene we found is the correct one, we assign it correctly + if (Path.GetFileNameWithoutExtension(path) == sceneName.stringValue) + { + sceneAsset = String.IsNullOrEmpty(sceneGUID) ? null : AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(sceneGUID)); + } + } + + EditorGUI.BeginChangeCheck(); sceneAsset = EditorGUI.ObjectField(rect, "Test Scene", sceneAsset, typeof(SceneAsset), false) as SceneAsset; - sceneName.stringValue = sceneAsset != null && !sceneAsset.Equals(null) ? sceneAsset.name : null; - scenePath.stringValue = AssetDatabase.GetAssetPath(sceneAsset); - sceneLabels.stringValue = GetLabelForAsset(sceneAsset); + if (EditorGUI.EndChangeCheck()) + { + sceneName.stringValue = sceneAsset != null && !sceneAsset.Equals(null) ? sceneAsset.name : null; + scenePath.stringValue = AssetDatabase.GetAssetPath(sceneAsset); + sceneLabels.stringValue = GetLabelForAsset(sceneAsset); + } // Enabled field rect.y += fieldHeight; From c9a0e21d8890875a5cd3e99de1b195ffd6009121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 30 Jun 2020 14:39:45 +0200 Subject: [PATCH 2/2] Added doc --- .../Runtime/PerformanceTestUtils.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/com.unity.testing.graphics-performance/Runtime/PerformanceTestUtils.cs b/com.unity.testing.graphics-performance/Runtime/PerformanceTestUtils.cs index d7383a20de8..a9b05f79153 100644 --- a/com.unity.testing.graphics-performance/Runtime/PerformanceTestUtils.cs +++ b/com.unity.testing.graphics-performance/Runtime/PerformanceTestUtils.cs @@ -9,6 +9,12 @@ public static class PerformanceTestUtils { public static TestSceneAsset testScenesAsset = PerformanceTestSettings.GetTestSceneDescriptionAsset(); + /// + /// Note that you need to call this function using yield return LoadScene(...) Otherwise the scene doesn't have the time to load properly. + /// + /// + /// + /// Call yield return LoadScene() public static IEnumerator LoadScene(string sceneName, RenderPipelineAsset hdAsset) { if (GraphicsSettings.renderPipelineAsset != hdAsset) @@ -20,6 +26,11 @@ public static IEnumerator LoadScene(string sceneName, RenderPipelineAsset hdAsse yield return null; } + /// + /// This function finds the PerformanceTestSceneSettings component in your scene and use it to allocate the render texture for the test camera. + /// Don't forget to call CleanupTestSceneIfNeeded to release the render texture. + /// + /// public static PerformanceTestSceneSettings SetupTestScene() { var sceneSettings = GameObject.FindObjectOfType(); @@ -39,6 +50,9 @@ public static PerformanceTestSceneSettings SetupTestScene() return sceneSettings; } + /// + /// Call this function to release the allocated render texture. + /// public static void CleanupTestSceneIfNeeded() { var settings = GameObject.FindObjectOfType();