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; 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();