< 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:0
Uncovered lines:35
Coverable lines:35
Total lines:94
Line coverage:0% (0 of 35)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:11
Method coverage:0% (0 of 11)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%2100%
Dispose()0%2100%
GetTipsView()0%2100%
GetPercentageView()0%2100%
GetTimeoutView()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    {
 12        [SerializeField] private LoadingScreenTipsView tipsView;
 13        [SerializeField] private LoadingScreenPercentageView percentageView;
 14        [SerializeField] private LoadingScreenTimeoutView timeoutView;
 15        [SerializeField] private RawImage rawImage;
 16        private RenderTexture renderTexture;
 17        private RectTransform rawImageRectTransform;
 18
 19        public event Action<ShowHideAnimator> OnFadeInFinish;
 20
 21        public void Start()
 22        {
 023            showHideAnimator.OnWillFinishStart += FadeInFinish;
 24
 025            rawImageRectTransform = rawImage.GetComponent<RectTransform>();
 026            SetupBlitTexture();
 027            FadeIn(true, false);
 028        }
 29
 30        public override void Dispose()
 31        {
 032            base.Dispose();
 033            showHideAnimator.OnWillFinishStart -= FadeInFinish;
 034        }
 35
 36        public LoadingScreenTipsView GetTipsView() =>
 037            tipsView;
 38
 39        public LoadingScreenPercentageView GetPercentageView() =>
 040            percentageView;
 41
 42        public ILoadingScreenTimeoutView GetTimeoutView() =>
 043            timeoutView;
 44
 45        public void FadeIn(bool instant, bool blitTexture)
 46        {
 047            if (isVisible) return;
 48
 49            //We blit the texture in case we need a static image when teleport starts
 050            if(blitTexture)
 051                BlitTexture();
 52
 053            Show(instant);
 054        }
 55
 56        public void FadeOut()
 57        {
 058            if (!isVisible) return;
 059            rawImage.gameObject.SetActive(false);
 60
 061            Hide();
 062        }
 63
 064        public override void RefreshControl() { }
 65
 66        private void FadeInFinish(ShowHideAnimator obj)
 67        {
 068            OnFadeInFinish?.Invoke(obj);
 069            rawImage.gameObject.SetActive(false);
 070        }
 71
 72        private void BlitTexture()
 73        {
 74            //We need to add this check just in case that the resolution has changed
 075            if (renderTexture.width != Screen.width || renderTexture.height != Screen.height)
 076                SetupBlitTexture();
 77
 078            Graphics.Blit(null, renderTexture);
 079            rawImage.gameObject.SetActive(true);
 080        }
 81
 82        private void SetupBlitTexture()
 83        {
 84            //Blit null works differently in WebGL than in desktop platform. We have to deal with it and rotate the resu
 085            if (Application.isEditor || Application.platform != RuntimePlatform.WebGLPlayer)
 086                rawImageRectTransform.eulerAngles = new Vector3(180, 0, 0);
 87
 088            if (renderTexture) renderTexture.Release();
 089            renderTexture = new RenderTexture(Screen.width, Screen.height, 0);
 090            rawImage.texture = renderTexture;
 091        }
 92
 93    }
 94}