| | 1 | | using Builder; |
| | 2 | | using Cinemachine; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Components; |
| | 5 | | using DCL.Configuration; |
| | 6 | | using DCL.Helpers; |
| | 7 | | using DCL.Models; |
| | 8 | | using Newtonsoft.Json; |
| | 9 | | using NUnit.Framework; |
| | 10 | | using System; |
| | 11 | | using System.Collections; |
| | 12 | | using System.Collections.Generic; |
| | 13 | | using UnityEngine; |
| | 14 | | using UnityEngine.TestTools; |
| | 15 | |
|
| | 16 | | public class BuilderInWorldShould : IntegrationTestSuite_Legacy |
| | 17 | | { |
| | 18 | | [Test] |
| | 19 | | public void GroundRaycast() |
| | 20 | | { |
| | 21 | | RaycastHit hit; |
| 1 | 22 | | BuilderInWorldController builderInWorldController = Resources.FindObjectsOfTypeAll<BuilderInWorldController>()[0 |
| 1 | 23 | | BuilderInWorldGodMode godMode = builderInWorldController.GetComponentInChildren<BuilderInWorldGodMode>(true); |
| | 24 | |
|
| 1 | 25 | | Vector3 fromPosition = new Vector3(0, 10, 0); |
| 1 | 26 | | Vector3 toPosition = Vector3.zero; |
| 1 | 27 | | Vector3 direction = toPosition - fromPosition; |
| | 28 | |
|
| 1 | 29 | | bool groundLayerFound = Physics.Raycast(fromPosition, direction, out hit, BuilderInWorldGodMode.RAYCAST_MAX_DIST |
| | 30 | |
|
| 1 | 31 | | UnityEngine.Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); |
| | 32 | |
|
| 1 | 33 | | if (Physics.Raycast(ray, out hit, BuilderInWorldGodMode.RAYCAST_MAX_DISTANCE, godMode.groundLayer)) |
| | 34 | | { |
| 1 | 35 | | groundLayerFound = true; |
| | 36 | | } |
| | 37 | |
|
| 1 | 38 | | Assert.IsTrue(groundLayerFound, "The ground layer is not set to Ground"); |
| 1 | 39 | | } |
| | 40 | |
|
| | 41 | | [Test] |
| | 42 | | public void SceneReferences() |
| | 43 | | { |
| 1 | 44 | | BuilderInWorldController builderInWorldController = Resources.FindObjectsOfTypeAll<BuilderInWorldController>()[0 |
| | 45 | |
|
| 1 | 46 | | Assert.IsNotNull(builderInWorldController.cursorGO, "References on the builder-in-world prefab are null, check t |
| 1 | 47 | | Assert.IsNotNull(builderInWorldController.inputController, "References on the builder-in-world prefab are null, |
| 1 | 48 | | Assert.IsNotNull(builderInWorldController.cameraParentGO, "References on the builder-in-world prefab are null, c |
| | 49 | |
|
| | 50 | |
|
| 1 | 51 | | BuilderInWorldGodMode godMode = builderInWorldController.GetComponentInChildren<BuilderInWorldGodMode>(); |
| | 52 | |
|
| 1 | 53 | | Assert.IsNotNull(godMode.avatarRenderer, "References on the builder-in-world prefab are null, check them all!"); |
| 1 | 54 | | Assert.IsNotNull(godMode.mouseCatcher, "References on the builder-in-world god mode are null, check them all!"); |
| 1 | 55 | | Assert.IsNotNull(godMode.cameraController, "References on the builder-in-world god mode are null, check them all |
| 1 | 56 | | Assert.IsNotNull(godMode.freeCameraController, "References on the builder-in-world god mode are null, check them |
| | 57 | |
|
| 1 | 58 | | DCLBuilderRaycast dCLBuilderRaycast = godMode.GetComponentInChildren<DCLBuilderRaycast>(); |
| | 59 | |
|
| 1 | 60 | | Assert.IsNotNull(dCLBuilderRaycast.builderCamera, "Camera reference on the builder-in-world god mode children ar |
| | 61 | |
|
| 1 | 62 | | VoxelController voxelController = godMode.GetComponent<VoxelController>(); |
| | 63 | |
|
| 1 | 64 | | Assert.IsNotNull(voxelController.freeCameraMovement, "Camera reference on the builder-in-world voxel controller |
| 1 | 65 | | } |
| | 66 | |
|
| | 67 | | [Test] |
| | 68 | | public void BuilderInWorldEntityComponents() |
| | 69 | | { |
| 1 | 70 | | string entityId = "1"; |
| 1 | 71 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| | 72 | |
|
| 1 | 73 | | DCLBuilderInWorldEntity biwEntity = Utils.GetOrCreateComponent<DCLBuilderInWorldEntity>(scene.entities[entityId] |
| 1 | 74 | | biwEntity.Init(scene.entities[entityId], null); |
| | 75 | |
|
| 1 | 76 | | Assert.IsTrue(biwEntity.entityUniqueId == scene.sceneData.id + scene.entities[entityId].entityId, "Entity id is |
| | 77 | |
|
| 1 | 78 | | SmartItemComponent.Model model = new SmartItemComponent.Model(); |
| | 79 | |
|
| 1 | 80 | | scene.EntityComponentCreateOrUpdateWithModel(entityId, CLASS_ID_COMPONENT.SMART_ITEM, model); |
| | 81 | |
|
| 1 | 82 | | Assert.IsTrue(biwEntity.HasSmartItemComponent()); |
| | 83 | |
|
| 1 | 84 | | DCLName name = (DCLName) scene.SharedComponentCreate(Guid.NewGuid().ToString(), Convert.ToInt32(CLASS_ID.NAME)); |
| 1 | 85 | | scene.SharedComponentAttach(biwEntity.rootEntity.entityId, name.id); |
| | 86 | |
|
| 1 | 87 | | DCLName dclName = biwEntity.rootEntity.TryGetComponent<DCLName>(); |
| 1 | 88 | | Assert.IsNotNull(dclName); |
| | 89 | |
|
| 1 | 90 | | string newName = "TestingName"; |
| 1 | 91 | | dclName.SetNewName(newName); |
| 1 | 92 | | Assert.AreEqual(newName, biwEntity.GetDescriptiveName()); |
| | 93 | |
|
| | 94 | |
|
| 1 | 95 | | DCLLockedOnEdit entityLocked = (DCLLockedOnEdit) scene.SharedComponentCreate(Guid.NewGuid().ToString(), Convert. |
| 1 | 96 | | scene.SharedComponentAttach(biwEntity.rootEntity.entityId, entityLocked.id); |
| | 97 | |
|
| 1 | 98 | | DCLLockedOnEdit dclLockedOnEdit = biwEntity.rootEntity.TryGetComponent<DCLLockedOnEdit>(); |
| 1 | 99 | | Assert.IsNotNull(dclLockedOnEdit); |
| | 100 | |
|
| 1 | 101 | | bool isLocked = true; |
| 1 | 102 | | dclLockedOnEdit.SetIsLocked(isLocked); |
| 1 | 103 | | Assert.AreEqual(biwEntity.IsLocked, isLocked); |
| 1 | 104 | | } |
| | 105 | |
|
| | 106 | | protected override IEnumerator TearDown() |
| | 107 | | { |
| 3 | 108 | | AssetCatalogBridge.i.ClearCatalog(); |
| 3 | 109 | | BIWCatalogManager.ClearCatalog(); |
| 3 | 110 | | yield return base.TearDown(); |
| 3 | 111 | | } |
| | 112 | | } |