| | 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; |
| 0 | 11 | | private BaseVariable<string> loadingMessage => DataStore.i.HUDs.loadingHUD.message; |
| 0 | 12 | | private BaseVariable<bool> isSignUpFlow => DataStore.i.common.isSignUpFlow; |
| | 13 | | private bool isDisposed = false; |
| | 14 | |
|
| 0 | 15 | | public PreloadingController() |
| | 16 | | { |
| 0 | 17 | | view = Object.Instantiate(GetView()); |
| 0 | 18 | | loadingMessage.OnChange += OnMessageChange; |
| 0 | 19 | | isSignUpFlow.OnChange += SignUpFlowChanged; |
| 0 | 20 | | } |
| | 21 | |
|
| | 22 | | private GameObject GetView() |
| | 23 | | { |
| 0 | 24 | | return Resources.Load<GameObject>("Preloading"); |
| | 25 | | } |
| | 26 | |
|
| | 27 | | public void Dispose() |
| | 28 | | { |
| 0 | 29 | | if (isDisposed) return; |
| 0 | 30 | | isDisposed = true; |
| 0 | 31 | | loadingMessage.OnChange -= OnMessageChange; |
| 0 | 32 | | isSignUpFlow.OnChange -= SignUpFlowChanged; |
| 0 | 33 | | Object.Destroy(view.gameObject); |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | private void OnMessageChange(string current, string previous) |
| | 37 | | { |
| 0 | 38 | | if (current.Contains("%")) |
| | 39 | | { |
| 0 | 40 | | Dispose(); |
| | 41 | | } |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | private void SignUpFlowChanged(bool current, bool previous) |
| | 45 | | { |
| 0 | 46 | | if (current) |
| | 47 | | { |
| 0 | 48 | | Dispose(); |
| | 49 | | } |
| 0 | 50 | | } |
| | 51 | | } |
| | 52 | | } |