< Summary

Class:DCL.LoadingScreen.LoadingScreenView
Assembly:DCL.LoadingScreen
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreen/Scripts/LoadingScreenView.cs
Covered lines:1
Uncovered lines:36
Coverable lines:37
Total lines:98
Line coverage:2.7% (1 of 37)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LoadingScreenView()0%110100%
Create()0%2100%
Start()0%6200%
Dispose()0%2100%
GetTipsView()0%2100%
GetPercentageView()0%2100%
FadeIn(...)0%12300%
FadeOut()0%6200%
RefreshControl()0%2100%
FadeInFinish(...)0%6200%
BlitTexture()0%12300%
SetupBlitTexture()0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreen/Scripts/LoadingScreenView.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5namespace DCL.LoadingScreen
 6{
 7    /// <summary>
 8    ///     Display the current state of the Loading Screen Controller
 9    /// </summary>
 10    public class LoadingScreenView : BaseComponentView, ILoadingScreenView
 11    {
 112        private static readonly string PATH = "_LoadingScreen";
 13
 14        [SerializeField] private LoadingScreenTipsView tipsView;
 15        [SerializeField] private LoadingScreenPercentageView percentageView;
 16        [SerializeField] private RawImage rawImage;
 17        [SerializeField] private GameObject betaTag;
 18        private RenderTexture renderTexture;
 19        private RectTransform rawImageRectTransform;
 20
 21        public event Action<ShowHideAnimator> OnFadeInFinish;
 22
 23        public static LoadingScreenView Create() =>
 024            Create<LoadingScreenView>(PATH);
 25
 26        public override void Start()
 27        {
 028            base.Start();
 029            showHideAnimator.OnWillFinishStart += FadeInFinish;
 30
 031            betaTag.SetActive(!Application.isEditor && Application.platform != RuntimePlatform.WebGLPlayer);
 32
 033            rawImageRectTransform = rawImage.GetComponent<RectTransform>();
 034            SetupBlitTexture();
 035            FadeIn(true, false);
 036        }
 37
 38        public override void Dispose()
 39        {
 040            base.Dispose();
 041            showHideAnimator.OnWillFinishStart -= FadeInFinish;
 042        }
 43
 44        public LoadingScreenTipsView GetTipsView() =>
 045            tipsView;
 46
 47        public LoadingScreenPercentageView GetPercentageView() =>
 048            percentageView;
 49
 50        public void FadeIn(bool instant, bool blitTexture)
 51        {
 052            if (isVisible) return;
 53
 54            //We blit the texture in case we need a static image when teleport starts
 055            if(blitTexture)
 056                BlitTexture();
 57
 058            Show(instant);
 059        }
 60
 61        public void FadeOut()
 62        {
 063            if (!isVisible) return;
 64
 065            Hide();
 066        }
 67
 068        public override void RefreshControl() { }
 69
 70        private void FadeInFinish(ShowHideAnimator obj)
 71        {
 072            OnFadeInFinish?.Invoke(obj);
 073            rawImage.gameObject.SetActive(false);
 074        }
 75
 76        private void BlitTexture()
 77        {
 78            //We need to add this check just in case that the resolution has changed
 079            if (renderTexture.width != Screen.width || renderTexture.height != Screen.height)
 080                SetupBlitTexture();
 81
 082            Graphics.Blit(null, renderTexture);
 083            rawImage.gameObject.SetActive(true);
 084        }
 85
 86        private void SetupBlitTexture()
 87        {
 88            //Blit null works differently in WebGL than in desktop platform. We have to deal with it and rotate the resu
 089            if (Application.isEditor || Application.platform != RuntimePlatform.WebGLPlayer)
 090                rawImageRectTransform.eulerAngles = new Vector3(180, 0, 0);
 91
 092            if (renderTexture) renderTexture.Release();
 093            renderTexture = new RenderTexture(Screen.width, Screen.height, 0);
 094            rawImage.texture = renderTexture;
 095        }
 96
 97    }
 98}