| | 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 | | { |
| | 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 | | { |
| 0 | 23 | | showHideAnimator.OnWillFinishStart += FadeInFinish; |
| | 24 | |
|
| 0 | 25 | | rawImageRectTransform = rawImage.GetComponent<RectTransform>(); |
| 0 | 26 | | SetupBlitTexture(); |
| 0 | 27 | | FadeIn(true, false); |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | public override void Dispose() |
| | 31 | | { |
| 0 | 32 | | base.Dispose(); |
| 0 | 33 | | showHideAnimator.OnWillFinishStart -= FadeInFinish; |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | public LoadingScreenTipsView GetTipsView() => |
| 0 | 37 | | tipsView; |
| | 38 | |
|
| | 39 | | public LoadingScreenPercentageView GetPercentageView() => |
| 0 | 40 | | percentageView; |
| | 41 | |
|
| | 42 | | public ILoadingScreenTimeoutView GetTimeoutView() => |
| 0 | 43 | | timeoutView; |
| | 44 | |
|
| | 45 | | public void FadeIn(bool instant, bool blitTexture) |
| | 46 | | { |
| 0 | 47 | | if (isVisible) return; |
| | 48 | |
|
| | 49 | | //We blit the texture in case we need a static image when teleport starts |
| 0 | 50 | | if(blitTexture) |
| 0 | 51 | | BlitTexture(); |
| | 52 | |
|
| 0 | 53 | | Show(instant); |
| 0 | 54 | | } |
| | 55 | |
|
| | 56 | | public void FadeOut() |
| | 57 | | { |
| 0 | 58 | | if (!isVisible) return; |
| 0 | 59 | | rawImage.gameObject.SetActive(false); |
| | 60 | |
|
| 0 | 61 | | Hide(); |
| 0 | 62 | | } |
| | 63 | |
|
| 0 | 64 | | public override void RefreshControl() { } |
| | 65 | |
|
| | 66 | | private void FadeInFinish(ShowHideAnimator obj) |
| | 67 | | { |
| 0 | 68 | | OnFadeInFinish?.Invoke(obj); |
| 0 | 69 | | rawImage.gameObject.SetActive(false); |
| 0 | 70 | | } |
| | 71 | |
|
| | 72 | | private void BlitTexture() |
| | 73 | | { |
| | 74 | | //We need to add this check just in case that the resolution has changed |
| 0 | 75 | | if (renderTexture.width != Screen.width || renderTexture.height != Screen.height) |
| 0 | 76 | | SetupBlitTexture(); |
| | 77 | |
|
| 0 | 78 | | Graphics.Blit(null, renderTexture); |
| 0 | 79 | | rawImage.gameObject.SetActive(true); |
| 0 | 80 | | } |
| | 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 |
| 0 | 85 | | if (Application.isEditor || Application.platform != RuntimePlatform.WebGLPlayer) |
| 0 | 86 | | rawImageRectTransform.eulerAngles = new Vector3(180, 0, 0); |
| | 87 | |
|
| 0 | 88 | | if (renderTexture) renderTexture.Release(); |
| 0 | 89 | | renderTexture = new RenderTexture(Screen.width, Screen.height, 0); |
| 0 | 90 | | rawImage.texture = renderTexture; |
| 0 | 91 | | } |
| | 92 | |
|
| | 93 | | } |
| | 94 | | } |