|
2 | 2 | using UnityEngine;
|
3 | 3 | using System;
|
4 | 4 | using System.Linq;
|
| 5 | +using UnityEditor; |
5 | 6 | using UnityEngine.Rendering;
|
6 | 7 | using static UnityEngine.TestTools.Graphics.Performance.PerformanceMetricNames;
|
7 | 8 |
|
8 | 9 | namespace UnityEngine.TestTools.Graphics.Performance
|
9 | 10 | {
|
10 | 11 | [CreateAssetMenu(menuName = "Testing/Performance Test Description")]
|
11 | 12 | public class TestSceneAsset : ScriptableObject
|
| 13 | + { |
| 14 | + |
| 15 | + [Serializable] |
| 16 | + public class SceneData |
| 17 | + { |
| 18 | + public string scene; |
| 19 | + public string sceneLabels; |
| 20 | + public string scenePath; //See also ScenePathUpdater |
| 21 | + public bool enabled; |
| 22 | + } |
| 23 | + |
| 24 | + [Serializable] |
| 25 | + public class SRPAssetData |
| 26 | + { |
| 27 | + public RenderPipelineAsset asset; |
| 28 | + public string assetLabels; |
| 29 | + public string alias; // reference named used in the test |
| 30 | + } |
| 31 | + |
| 32 | + [Serializable] |
| 33 | + public class SRPAssetDataAliasByHand : SRPAssetData { } |
| 34 | + |
| 35 | + [Serializable] |
| 36 | + public class TestSuiteData |
12 | 37 | {
|
13 |
| - [Serializable] |
14 |
| - public class SceneData |
15 |
| - { |
16 |
| - public string scene; |
17 |
| - public string sceneLabels; |
18 |
| - public string scenePath; |
19 |
| - public bool enabled; |
20 |
| - } |
| 38 | + public List<SceneData> scenes; |
| 39 | + public List<SRPAssetData> srpAssets; |
21 | 40 |
|
22 |
| - [Serializable] |
23 |
| - public class SRPAssetData |
| 41 | + public IEnumerable<(SceneData sceneData, SRPAssetData assetData)> GetTestList() |
24 | 42 | {
|
25 |
| - public RenderPipelineAsset asset; |
26 |
| - public string assetLabels; |
27 |
| - public string alias; // reference named used in the test |
| 43 | + foreach (var srpAsset in srpAssets) |
| 44 | + foreach (var scene in scenes) |
| 45 | + if (scene.enabled) |
| 46 | + yield return (scene, srpAsset); |
28 | 47 | }
|
| 48 | + } |
29 | 49 |
|
30 |
| - [Serializable] |
31 |
| - public class TestSuiteData |
32 |
| - { |
33 |
| - public List<SceneData> scenes; |
34 |
| - public List<SRPAssetData> srpAssets; |
35 |
| - |
36 |
| - public IEnumerable<(SceneData sceneData, SRPAssetData assetData)> GetTestList() |
37 |
| - { |
38 |
| - foreach (var srpAsset in srpAssets) |
39 |
| - foreach (var scene in scenes) |
40 |
| - if (scene.enabled) |
41 |
| - yield return (scene, srpAsset); |
42 |
| - } |
43 |
| - } |
| 50 | + // Store the name of the scenes so we can load them at runtime |
| 51 | + public TestSuiteData counterTestSuite = new TestSuiteData(); |
| 52 | + public TestSuiteData memoryTestSuite = new TestSuiteData(); |
| 53 | + public TestSuiteData buildTestSuite = new TestSuiteData(); |
| 54 | + |
| 55 | + public List<SRPAssetDataAliasByHand> srpAssetAliases = new List<SRPAssetDataAliasByHand>(); |
| 56 | + public List<SceneData> additionalLoadableScenes = new List<SceneData>(); |
44 | 57 |
|
45 |
| - // Store the name of the scenes so we can load them at runtime |
46 |
| - public TestSuiteData counterTestSuite = new TestSuiteData(); |
47 |
| - public TestSuiteData memoryTestSuite = new TestSuiteData(); |
48 |
| - public TestSuiteData buildTestSuite = new TestSuiteData(); |
| 58 | + public IEnumerable<(SceneData sceneData, SRPAssetData assetData)> GetAllTests() |
| 59 | + { |
| 60 | + foreach (var test in counterTestSuite.GetTestList()) |
| 61 | + yield return test; |
| 62 | + foreach (var test in memoryTestSuite.GetTestList()) |
| 63 | + yield return test; |
| 64 | + foreach (var test in buildTestSuite.GetTestList()) |
| 65 | + yield return test; |
| 66 | + } |
49 | 67 |
|
50 |
| - public List<SRPAssetData> srpAssetAliases = new List<SRPAssetData>(); |
| 68 | + public string GetScenePath(string sceneName) |
| 69 | + => GetAllTests().FirstOrDefault(s => s.sceneData.scene == sceneName).sceneData?.scenePath |
| 70 | + ?? additionalLoadableScenes.FirstOrDefault(s => s.scene == sceneName)?.scenePath; |
51 | 71 |
|
52 |
| - public IEnumerable<(SceneData sceneData, SRPAssetData assetData)> GetAllTests() |
53 |
| - { |
54 |
| - foreach (var test in counterTestSuite.GetTestList()) |
55 |
| - yield return test; |
56 |
| - foreach (var test in memoryTestSuite.GetTestList()) |
57 |
| - yield return test; |
58 |
| - foreach (var test in buildTestSuite.GetTestList()) |
59 |
| - yield return test; |
60 |
| - } |
| 72 | + public string GetSRPAssetAlias(RenderPipelineAsset srpAsset) |
| 73 | + => srpAssetAliases.Where(a => a.asset == srpAsset).FirstOrDefault()?.alias; |
| 74 | + |
| 75 | + IEnumerable<SceneData> GetAllSceneData() |
| 76 | + { |
| 77 | + foreach (var scene in counterTestSuite.scenes) |
| 78 | + yield return scene; |
| 79 | + foreach (var scene in memoryTestSuite.scenes) |
| 80 | + yield return scene; |
| 81 | + foreach (var scene in buildTestSuite.scenes) |
| 82 | + yield return scene; |
| 83 | + foreach (var scene in additionalLoadableScenes) |
| 84 | + yield return scene; |
| 85 | + } |
61 | 86 |
|
62 |
| - public string GetScenePath(string sceneName) => GetAllTests().FirstOrDefault(s => s.sceneData.scene == sceneName).sceneData?.scenePath; |
| 87 | +#if UNITY_EDITOR |
| 88 | + public UnityEditor.EditorBuildSettingsScene[] ConvertTestDataScenesToBuildSettings() |
| 89 | + { |
| 90 | + var scenesForTests = GetAllSceneData(); |
63 | 91 |
|
64 |
| - public string GetSRPAssetAlias(RenderPipelineAsset srpAsset) => srpAssetAliases.Where(a => a.asset == srpAsset).FirstOrDefault()?.alias; |
| 92 | + var scenesForTestsConvertedBuildSettingsScenes = |
| 93 | + scenesForTests.Select(x => new EditorBuildSettingsScene(x.scenePath, x.enabled)).ToArray(); |
| 94 | + |
| 95 | + return scenesForTestsConvertedBuildSettingsScenes; |
65 | 96 | }
|
66 | 97 |
|
| 98 | +#endif |
| 99 | +} |
67 | 100 | public struct CounterTestDescription
|
68 | 101 | {
|
69 | 102 | public TestSceneAsset.SceneData sceneData;
|
|
0 commit comments