< Summary

Class:DCL.MapChunk
Assembly:MapRenderer
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/MapRenderer/MapChunk.cs
Covered lines:0
Uncovered lines:38
Coverable lines:38
Total lines:95
Line coverage:0% (0 of 38)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:3
Method coverage:0% (0 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LoadChunkImage()0%2100%
UpdateCulling()0%42600%
OnDestroy()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/MapRenderer/MapChunk.cs

#LineLine coverage
 1using DCL.Helpers;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5namespace DCL
 6{
 7    public class MapChunk : MonoBehaviour
 8    {
 9        private bool VERBOSE = false;
 10        const string MAP_API_BASE = "https://api.decentraland.org/v1/map.png";
 11
 12        public RawImage targetImage;
 13
 14        [System.NonSerialized] public Vector2Int center;
 15        [System.NonSerialized] public Vector2Int size;
 16        [System.NonSerialized] public int tileSize;
 17        [System.NonSerialized] public MapAtlas owner;
 18        protected RectTransform rt;
 19        protected bool isLoadingOrLoaded = false;
 20        private IWebRequestAsyncOperation loadOp;
 21
 22        public virtual IWebRequestAsyncOperation LoadChunkImage()
 23        {
 024            isLoadingOrLoaded = true;
 25
 026            string url = $"{MAP_API_BASE}?center={center.x},{center.y}&width={size.x}&height={size.y}&size={tileSize}";
 27
 028            Texture2D result = null;
 29
 030            return Utils.FetchTexture(url, false, (x) =>
 31            {
 032                result = x;
 33
 034                if (result == null)
 035                    return;
 36
 037                targetImage.texture = result;
 038                targetImage.texture.wrapMode = TextureWrapMode.Clamp;
 039                targetImage.SetNativeSize();
 040                targetImage.color = Color.white;
 041            });
 42        }
 43
 44        public void UpdateCulling()
 45        {
 046            if (owner == null)
 047                return;
 48
 049            if (rt == null)
 050                rt = transform as RectTransform;
 51
 052            Vector2 myMinCoords = rt.TransformPoint(new Vector3(rt.rect.xMin, rt.rect.yMin));
 053            Vector2 myMaxCoords = rt.TransformPoint(new Vector3(rt.rect.xMax, rt.rect.yMax));
 54
 055            Vector2 viewMinCoords = owner.viewport.TransformPoint(new Vector3(owner.viewport.rect.xMin, owner.viewport.r
 056            Vector2 viewMaxCoords = owner.viewport.TransformPoint(new Vector3(owner.viewport.rect.xMax, owner.viewport.r
 57
 58#if UNITY_EDITOR
 059            if (VERBOSE)
 60            {
 061                var rtWorldRect = new Rect(myMinCoords.x, myMinCoords.y, myMaxCoords.x - myMinCoords.x, myMaxCoords.y - 
 062                Utils.DrawRectGizmo(rtWorldRect, Color.red, 5f);
 63            }
 64#endif
 065            float size = (viewMaxCoords - viewMinCoords).magnitude;
 66
 067            Rect viewportRect = new Rect(viewMinCoords, viewMaxCoords - viewMinCoords);
 068            viewportRect.min -= Vector2.one * size;
 069            viewportRect.max += Vector2.one * size;
 70
 71#if UNITY_EDITOR
 072            if (VERBOSE)
 73            {
 074                Utils.DrawRectGizmo(viewportRect, Color.blue, 5f);
 75            }
 76#endif
 77
 078            Rect myRect = new Rect(myMinCoords, myMaxCoords - myMinCoords);
 079            bool visible = viewportRect.Overlaps(myRect, true);
 80
 081            targetImage.enabled = visible;
 82
 083            if (!isLoadingOrLoaded)
 84            {
 085                loadOp = LoadChunkImage();
 86            }
 087        }
 88
 89        private void OnDestroy()
 90        {
 091            if (loadOp != null)
 092                loadOp.Dispose();
 093        }
 94    }
 95}