| | 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 | |
|
| 249 | 13 | | public SceneDebugPlane(LoadParcelScenesMessage.UnityParcelScene sceneData, Transform parent) |
| | 14 | | { |
| 249 | 15 | | int sceneDataParcelsLength = sceneData.parcels.Length; |
| 249 | 16 | | sceneParcelPlanes = new GameObject[sceneDataParcelsLength]; |
| | 17 | |
|
| 1020 | 18 | | for (int j = 0; j < sceneDataParcelsLength; j++) |
| | 19 | | { |
| 261 | 20 | | GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane); |
| 261 | 21 | | sceneParcelPlanes[j] = plane; |
| | 22 | |
|
| 261 | 23 | | UnityEngine.Object.Destroy(plane.GetComponent<MeshCollider>()); |
| | 24 | |
|
| 261 | 25 | | plane.name = $"parcel:{sceneData.parcels[j].x},{sceneData.parcels[j].y}"; |
| | 26 | |
|
| 261 | 27 | | plane.transform.SetParent(parent); |
| | 28 | |
|
| | 29 | | // the plane mesh with scale 1 occupies a 10 units space |
| 261 | 30 | | plane.transform.localScale = new Vector3(ParcelSettings.PARCEL_SIZE * 0.1f, 1f, |
| | 31 | | ParcelSettings.PARCEL_SIZE * 0.1f); |
| | 32 | |
|
| 261 | 33 | | Vector3 position = Utils.GridToWorldPosition(sceneData.parcels[j].x, sceneData.parcels[j].y); |
| | 34 | | // SET TO A POSITION RELATIVE TO basePosition |
| | 35 | |
|
| 261 | 36 | | position.Set(position.x + ParcelSettings.PARCEL_SIZE / 2, ParcelSettings.DEBUG_FLOOR_HEIGHT, |
| | 37 | | position.z + ParcelSettings.PARCEL_SIZE / 2); |
| | 38 | |
|
| 261 | 39 | | plane.transform.position = PositionUtils.WorldToUnityPosition(position); |
| | 40 | |
|
| 261 | 41 | | plane.GetComponent<MeshRenderer>().sharedMaterial = Utils.EnsureResourcesMaterial("Materials/DefaultPlan |
| | 42 | | } |
| 249 | 43 | | } |
| | 44 | |
|
| | 45 | | public void Dispose() |
| | 46 | | { |
| 249 | 47 | | if (sceneParcelPlanes == null) |
| | 48 | | { |
| 0 | 49 | | return; |
| | 50 | | } |
| | 51 | |
|
| 1020 | 52 | | for (int i = 0; i < sceneParcelPlanes.Length; i++) |
| | 53 | | { |
| 261 | 54 | | UnityEngine.Object.Destroy(sceneParcelPlanes[i]); |
| | 55 | | } |
| | 56 | |
|
| 249 | 57 | | sceneParcelPlanes = null; |
| 249 | 58 | | } |
| | 59 | | } |
| | 60 | | } |