| | 1 | | using System; |
| | 2 | | using DCL.Configuration; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCL.Models; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Controllers.ParcelSceneDebug |
| | 8 | | { |
| | 9 | | public class SceneDebugPlane : IDisposable |
| | 10 | | { |
| | 11 | | GameObject[] sceneParcelPlanes; |
| | 12 | |
|
| 386 | 13 | | public SceneDebugPlane(LoadParcelScenesMessage.UnityParcelScene sceneData, Transform parent) |
| | 14 | | { |
| 386 | 15 | | int sceneDataParcelsLength = sceneData.parcels.Length; |
| 386 | 16 | | sceneParcelPlanes = new GameObject[sceneDataParcelsLength]; |
| | 17 | |
|
| 1560 | 18 | | for (int j = 0; j < sceneDataParcelsLength; j++) |
| | 19 | | { |
| 394 | 20 | | GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane); |
| 394 | 21 | | sceneParcelPlanes[j] = plane; |
| | 22 | |
|
| 394 | 23 | | UnityEngine.Object.Destroy(plane.GetComponent<MeshCollider>()); |
| | 24 | |
|
| 394 | 25 | | plane.name = $"parcel:{sceneData.parcels[j].x},{sceneData.parcels[j].y}"; |
| | 26 | |
|
| 394 | 27 | | plane.transform.SetParent(parent); |
| | 28 | |
|
| | 29 | | // the plane mesh with scale 1 occupies a 10 units space |
| 394 | 30 | | plane.transform.localScale = new Vector3(ParcelSettings.PARCEL_SIZE * 0.1f, 1f, |
| | 31 | | ParcelSettings.PARCEL_SIZE * 0.1f); |
| | 32 | |
|
| 394 | 33 | | Vector3 position = Utils.GridToWorldPosition(sceneData.parcels[j].x, sceneData.parcels[j].y); |
| | 34 | | // SET TO A POSITION RELATIVE TO basePosition |
| | 35 | |
|
| 394 | 36 | | position.Set(position.x + ParcelSettings.PARCEL_SIZE / 2, ParcelSettings.DEBUG_FLOOR_HEIGHT, |
| | 37 | | position.z + ParcelSettings.PARCEL_SIZE / 2); |
| | 38 | |
|
| 394 | 39 | | plane.transform.position = PositionUtils.WorldToUnityPosition(position); |
| | 40 | |
|
| 394 | 41 | | if (DCL.Configuration.ParcelSettings.VISUAL_LOADING_ENABLED) |
| | 42 | | { |
| 0 | 43 | | Material finalMaterial = Utils.EnsureResourcesMaterial("Materials/DefaultPlane"); |
| 0 | 44 | | var matTransition = plane.AddComponent<MaterialTransitionController>(); |
| 0 | 45 | | matTransition.delay = 0; |
| 0 | 46 | | matTransition.useHologram = false; |
| 0 | 47 | | matTransition.fadeThickness = 20; |
| 0 | 48 | | matTransition.OnDidFinishLoading(finalMaterial); |
| 0 | 49 | | } |
| | 50 | | else |
| | 51 | | { |
| 394 | 52 | | plane.GetComponent<MeshRenderer>().sharedMaterial = |
| | 53 | | Utils.EnsureResourcesMaterial("Materials/DefaultPlane"); |
| | 54 | | } |
| | 55 | | } |
| 386 | 56 | | } |
| | 57 | |
|
| | 58 | | public void Dispose() |
| | 59 | | { |
| 377 | 60 | | if (sceneParcelPlanes == null) |
| | 61 | | { |
| 0 | 62 | | return; |
| | 63 | | } |
| | 64 | |
|
| 1524 | 65 | | for (int i = 0; i < sceneParcelPlanes.Length; i++) |
| | 66 | | { |
| 385 | 67 | | UnityEngine.Object.Destroy(sceneParcelPlanes[i]); |
| | 68 | | } |
| | 69 | |
|
| 377 | 70 | | sceneParcelPlanes = null; |
| 377 | 71 | | } |
| | 72 | | } |
| | 73 | | } |