| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | namespace DCL.LoadingScreen |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// Display the current state of the Loading Screen Controller |
| | 9 | | /// </summary> |
| | 10 | | public class LoadingScreenView : BaseComponentView, ILoadingScreenView |
| | 11 | | { |
| 1 | 12 | | 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() => |
| 0 | 24 | | Create<LoadingScreenView>(PATH); |
| | 25 | |
|
| | 26 | | public override void Start() |
| | 27 | | { |
| 0 | 28 | | base.Start(); |
| 0 | 29 | | showHideAnimator.OnWillFinishStart += FadeInFinish; |
| | 30 | |
|
| 0 | 31 | | betaTag.SetActive(!Application.isEditor && Application.platform != RuntimePlatform.WebGLPlayer); |
| | 32 | |
|
| 0 | 33 | | rawImageRectTransform = rawImage.GetComponent<RectTransform>(); |
| 0 | 34 | | SetupBlitTexture(); |
| 0 | 35 | | FadeIn(true, false); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | public override void Dispose() |
| | 39 | | { |
| 0 | 40 | | base.Dispose(); |
| 0 | 41 | | showHideAnimator.OnWillFinishStart -= FadeInFinish; |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public LoadingScreenTipsView GetTipsView() => |
| 0 | 45 | | tipsView; |
| | 46 | |
|
| | 47 | | public LoadingScreenPercentageView GetPercentageView() => |
| 0 | 48 | | percentageView; |
| | 49 | |
|
| | 50 | | public void FadeIn(bool instant, bool blitTexture) |
| | 51 | | { |
| 0 | 52 | | if (isVisible) return; |
| | 53 | |
|
| | 54 | | //We blit the texture in case we need a static image when teleport starts |
| 0 | 55 | | if(blitTexture) |
| 0 | 56 | | BlitTexture(); |
| | 57 | |
|
| 0 | 58 | | Show(instant); |
| 0 | 59 | | } |
| | 60 | |
|
| | 61 | | public void FadeOut() |
| | 62 | | { |
| 0 | 63 | | if (!isVisible) return; |
| | 64 | |
|
| 0 | 65 | | Hide(); |
| 0 | 66 | | } |
| | 67 | |
|
| 0 | 68 | | public override void RefreshControl() { } |
| | 69 | |
|
| | 70 | | private void FadeInFinish(ShowHideAnimator obj) |
| | 71 | | { |
| 0 | 72 | | OnFadeInFinish?.Invoke(obj); |
| 0 | 73 | | rawImage.gameObject.SetActive(false); |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | private void BlitTexture() |
| | 77 | | { |
| | 78 | | //We need to add this check just in case that the resolution has changed |
| 0 | 79 | | if (renderTexture.width != Screen.width || renderTexture.height != Screen.height) |
| 0 | 80 | | SetupBlitTexture(); |
| | 81 | |
|
| 0 | 82 | | Graphics.Blit(null, renderTexture); |
| 0 | 83 | | rawImage.gameObject.SetActive(true); |
| 0 | 84 | | } |
| | 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 |
| 0 | 89 | | if (Application.isEditor || Application.platform != RuntimePlatform.WebGLPlayer) |
| 0 | 90 | | rawImageRectTransform.eulerAngles = new Vector3(180, 0, 0); |
| | 91 | |
|
| 0 | 92 | | if (renderTexture) renderTexture.Release(); |
| 0 | 93 | | renderTexture = new RenderTexture(Screen.width, Screen.height, 0); |
| 0 | 94 | | rawImage.texture = renderTexture; |
| 0 | 95 | | } |
| | 96 | |
|
| | 97 | | } |
| | 98 | | } |