Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using static PerformanceMetricNames;
using Object = UnityEngine.Object;
using System.IO;

[CustomEditor(typeof(TestSceneAsset))]
class TestSceneAssetEditor : Editor
Expand Down Expand Up @@ -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<SceneAsset>(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<SceneAsset>(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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public static class PerformanceTestUtils
{
public static TestSceneAsset testScenesAsset = PerformanceTestSettings.GetTestSceneDescriptionAsset();

/// <summary>
/// Note that you need to call this function using yield return LoadScene(...) Otherwise the scene doesn't have the time to load properly.
/// </summary>
/// <param name="sceneName"></param>
/// <param name="hdAsset"></param>
/// <returns>Call yield return LoadScene()</returns>
public static IEnumerator LoadScene(string sceneName, RenderPipelineAsset hdAsset)
{
if (GraphicsSettings.renderPipelineAsset != hdAsset)
Expand All @@ -20,6 +26,11 @@ public static IEnumerator LoadScene(string sceneName, RenderPipelineAsset hdAsse
yield return null;
}

/// <summary>
/// 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.
/// </summary>
/// <returns></returns>
public static PerformanceTestSceneSettings SetupTestScene()
{
var sceneSettings = GameObject.FindObjectOfType<PerformanceTestSceneSettings>();
Expand All @@ -39,6 +50,9 @@ public static PerformanceTestSceneSettings SetupTestScene()
return sceneSettings;
}

/// <summary>
/// Call this function to release the allocated render texture.
/// </summary>
public static void CleanupTestSceneIfNeeded()
{
var settings = GameObject.FindObjectOfType<PerformanceTestSceneSettings>();
Expand Down