| | 1 | | using DCL.Components; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using System.Collections; |
| | 5 | | using DCL; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | public class UIVisualTestsBase : VisualTestsBase |
| | 9 | | { |
| | 10 | | protected string screenSpaceId; |
| | 11 | |
|
| | 12 | | protected IEnumerator InitUIVisualTestScene(string testName) |
| | 13 | | { |
| 6 | 14 | | VisualTestHelpers.snapshotIndex = 0; |
| 6 | 15 | | VisualTestHelpers.currentTestName = testName; |
| | 16 | |
|
| 6 | 17 | | yield return InitScene(); |
| | 18 | |
|
| | 19 | | //NOTE(Brian): If we don't wait a frame, RenderingController.Awake sets the rendering state back to false. |
| 6 | 20 | | yield return null; |
| | 21 | |
|
| 6 | 22 | | RenderProfileManifest.i.Initialize(RenderProfileManifest.i.testProfile); |
| | 23 | |
|
| 6 | 24 | | base.SetUp_Renderer(); |
| | 25 | |
|
| | 26 | | // Create UIScreenSpace |
| 6 | 27 | | UIScreenSpace screenSpace = TestHelpers.SharedComponentCreate<UIScreenSpace, UIScreenSpace.Model>(scene, CLASS_I |
| 6 | 28 | | yield return screenSpace.routine; |
| | 29 | |
|
| 6 | 30 | | screenSpaceId = screenSpace.id; |
| | 31 | |
|
| | 32 | | // The canvas has to be in ScreenSpaceCamera mode to be able to render the UI correctly for the snapshots |
| 6 | 33 | | screenSpace.canvas.renderMode = RenderMode.ScreenSpaceCamera; |
| 6 | 34 | | screenSpace.canvas.worldCamera = VisualTestController.i.camera; |
| 6 | 35 | | screenSpace.canvas.planeDistance = 1; |
| | 36 | |
|
| | 37 | | // The camera should only render UI to decrease conflict chance with future ground changes, etc. |
| 6 | 38 | | VisualTestController.i.camera.cullingMask = 1 << LayerMask.NameToLayer("UI"); |
| | 39 | |
|
| 6 | 40 | | int id = GameViewUtils.AddOrGetCustomSize(GameViewUtils.GameViewSizeType.FixedResolution, UnityEditor.GameViewSi |
| 6 | 41 | | GameViewUtils.SetSize(id); |
| 6 | 42 | | } |
| | 43 | |
|
| | 44 | | protected IEnumerator CreateUIComponent<SharedComponentType, SharedComponentModel>(CLASS_ID classId, SharedComponent |
| | 45 | | where SharedComponentType : BaseDisposable |
| | 46 | | where SharedComponentModel : class, new() |
| | 47 | | { |
| | 48 | | if (model == null) |
| | 49 | | model = new SharedComponentModel(); |
| | 50 | |
|
| | 51 | | // Creation |
| | 52 | | var component = scene.SharedComponentCreate( |
| | 53 | | componentId, |
| | 54 | | (int) classId |
| | 55 | | ) as SharedComponentType; |
| | 56 | | yield return component.routine; |
| | 57 | |
|
| | 58 | | // "fake" update (triggers 1st ApplyChanges() call) |
| | 59 | | scene.SharedComponentUpdate(componentId, JsonUtility.ToJson(new SharedComponentModel())); |
| | 60 | | yield return component.routine; |
| | 61 | |
|
| | 62 | | // "real" update |
| | 63 | | scene.SharedComponentUpdate(componentId, JsonUtility.ToJson(model)); |
| | 64 | | yield return component.routine; |
| | 65 | | } |
| | 66 | | } |