| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public class LoadingHUDView : MonoBehaviour |
| | 8 | | { |
| | 9 | | [SerializeField] internal TextMeshProUGUI text; |
| | 10 | | [SerializeField] internal Image loadingBar; |
| | 11 | | [SerializeField] internal GameObject tipsContainer; |
| | 12 | | [SerializeField] internal GameObject noTipsContainer; |
| | 13 | | [SerializeField] internal ShowHideAnimator showHideAnimator; |
| | 14 | |
|
| | 15 | | private bool isDestroyed = false; |
| | 16 | |
|
| | 17 | | public static LoadingHUDView CreateView() |
| | 18 | | { |
| 6 | 19 | | LoadingHUDView view = Instantiate(Resources.Load<GameObject>("LoadingHUD")).GetComponent<LoadingHUDView>(); |
| 6 | 20 | | view.gameObject.name = "_LoadingHUD"; |
| 6 | 21 | | return view; |
| | 22 | | } |
| | 23 | |
|
| | 24 | | public void Initialize() |
| | 25 | | { |
| 7 | 26 | | SetMessage(""); |
| 7 | 27 | | SetPercentage(0); |
| 7 | 28 | | SetTips(false); |
| 7 | 29 | | } |
| | 30 | |
|
| | 31 | | private void OnFinishHide(ShowHideAnimator obj) |
| | 32 | | { |
| 0 | 33 | | showHideAnimator.OnWillFinishHide -= OnFinishHide; |
| 0 | 34 | | DataStore.i.HUDs.loadingHUD.fadeIn.Set(false); |
| 0 | 35 | | DataStore.i.HUDs.loadingHUD.fadeOut.Set(false); |
| 0 | 36 | | DataStore.i.HUDs.loadingHUD.visible.Set(false); |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | private void OnFinishStart(ShowHideAnimator obj) |
| | 40 | | { |
| 0 | 41 | | showHideAnimator.OnWillFinishStart -= OnFinishStart; |
| 0 | 42 | | CommonScriptableObjects.isLoadingHUDOpen.Set(true); |
| 0 | 43 | | DataStore.i.HUDs.loadingHUD.fadeIn.Set(false); |
| 0 | 44 | | DataStore.i.HUDs.loadingHUD.fadeOut.Set(false); |
| 0 | 45 | | DataStore.i.HUDs.loadingHUD.visible.Set(true); |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | public void SetVisible(bool isVisible, bool instant) { |
| 9 | 49 | | if (isVisible) |
| | 50 | | { |
| 2 | 51 | | showHideAnimator.OnWillFinishStart += OnFinishStart; |
| 2 | 52 | | showHideAnimator.Show(instant); |
| 2 | 53 | | } |
| | 54 | | else |
| | 55 | | { |
| 7 | 56 | | showHideAnimator.OnWillFinishHide += OnFinishHide; |
| 7 | 57 | | showHideAnimator.Hide(instant); |
| 7 | 58 | | CommonScriptableObjects.isLoadingHUDOpen.Set(false); |
| | 59 | | } |
| 7 | 60 | | } |
| | 61 | |
|
| 30 | 62 | | public void SetMessage(string message) { text.text = message; } |
| 28 | 63 | | public void SetPercentage(float percentage) { loadingBar.transform.localScale = new Vector3(percentage, 1, 1); } |
| | 64 | | public void SetTips(bool showTips) |
| | 65 | | { |
| 16 | 66 | | tipsContainer.gameObject.SetActive(showTips); |
| 16 | 67 | | noTipsContainer.gameObject.SetActive(!showTips); |
| 16 | 68 | | } |
| | 69 | |
|
| 26 | 70 | | private void OnDestroy() { isDestroyed = true; } |
| | 71 | |
|
| | 72 | | public void Dispose() |
| | 73 | | { |
| 1 | 74 | | showHideAnimator.OnWillFinishHide -= OnFinishHide; |
| 1 | 75 | | showHideAnimator.OnWillFinishStart -= OnFinishStart; |
| 1 | 76 | | if (isDestroyed) |
| 0 | 77 | | return; |
| 1 | 78 | | isDestroyed = true; |
| 1 | 79 | | Destroy(gameObject); |
| 1 | 80 | | } |
| | 81 | | } |