| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using UnityEngine; |
| | 4 | | using Object = UnityEngine.Object; |
| | 5 | |
|
| | 6 | | namespace MainScripts.DCL.Controllers.HUD.Preloading |
| | 7 | | { |
| | 8 | | public class PreloadingController : IDisposable |
| | 9 | | { |
| | 10 | | private GameObject view; |
| | 11 | | private readonly DataStoreRef<DataStore_LoadingScreen> loadingScreenRef; |
| | 12 | |
|
| 0 | 13 | | private BaseVariable<bool> isSignUpFlow => DataStore.i.common.isSignUpFlow; |
| | 14 | | private bool isDisposed = false; |
| | 15 | |
|
| 0 | 16 | | public PreloadingController() |
| | 17 | | { |
| 0 | 18 | | view = Object.Instantiate(GetView()); |
| 0 | 19 | | loadingScreenRef.Ref.loadingHUD.message.OnChange += OnMessageChange; |
| 0 | 20 | | loadingScreenRef.Ref.decoupledLoadingHUD.visible.OnChange += OnDecoupledLoadingScreenVisibilityChange; |
| 0 | 21 | | isSignUpFlow.OnChange += SignUpFlowChanged; |
| 0 | 22 | | } |
| | 23 | |
|
| | 24 | | private void OnDecoupledLoadingScreenVisibilityChange(bool current, bool _) |
| | 25 | | { |
| 0 | 26 | | if(current) |
| 0 | 27 | | Dispose(); |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | private GameObject GetView() |
| | 31 | | { |
| 0 | 32 | | return Resources.Load<GameObject>("Preloading"); |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public void Dispose() |
| | 36 | | { |
| 0 | 37 | | if (isDisposed) return; |
| 0 | 38 | | isDisposed = true; |
| 0 | 39 | | loadingScreenRef.Ref.loadingHUD.message.OnChange -= OnMessageChange; |
| 0 | 40 | | loadingScreenRef.Ref.decoupledLoadingHUD.visible.OnChange -= OnDecoupledLoadingScreenVisibilityChange; |
| 0 | 41 | | isSignUpFlow.OnChange -= SignUpFlowChanged; |
| 0 | 42 | | Object.Destroy(view.gameObject); |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | private void OnMessageChange(string current, string previous) |
| | 46 | | { |
| 0 | 47 | | if (current.Contains("%")) |
| 0 | 48 | | Dispose(); |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | private void SignUpFlowChanged(bool current, bool previous) |
| | 52 | | { |
| 0 | 53 | | if (current) |
| 0 | 54 | | Dispose(); |
| 0 | 55 | | } |
| | 56 | | } |
| | 57 | | } |