| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | namespace LoadingHUD |
| | 6 | | { |
| | 7 | | public interface ILoadingHUDView |
| | 8 | | { |
| | 9 | | void SetVisible(bool isVisible); |
| | 10 | | void SetMessage(string message); |
| | 11 | | void SetPercentage(float percentage); |
| | 12 | | void SetWalletPrompt(bool showWalletPrompt); |
| | 13 | | void SetTips(bool showTips); |
| | 14 | | void Dispose(); |
| | 15 | | } |
| | 16 | |
|
| | 17 | | public class LoadingHUDView : MonoBehaviour, ILoadingHUDView |
| | 18 | | { |
| | 19 | | [SerializeField] internal TextMeshProUGUI text; |
| | 20 | | [SerializeField] internal Image loadingBar; |
| | 21 | | [SerializeField] internal GameObject walletPrompt; |
| | 22 | | [SerializeField] internal GameObject tipsContainer; |
| | 23 | | [SerializeField] internal GameObject noTipsContainer; |
| | 24 | |
|
| | 25 | | private bool isDestroyed = false; |
| | 26 | |
|
| | 27 | | public static ILoadingHUDView CreateView() |
| | 28 | | { |
| 1 | 29 | | LoadingHUDView view = Instantiate(Resources.Load<GameObject>("LoadingHUD")).GetComponent<LoadingHUDView>(); |
| 1 | 30 | | view.gameObject.name = "_LoadingHUD"; |
| 1 | 31 | | return view; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | private void Awake() |
| | 35 | | { |
| 9 | 36 | | SetMessage(""); |
| 9 | 37 | | SetPercentage(0); |
| 9 | 38 | | SetWalletPrompt(false); |
| 9 | 39 | | SetTips(false); |
| 9 | 40 | | } |
| | 41 | |
|
| 8 | 42 | | public void SetVisible(bool isVisible) { gameObject.SetActive(isVisible); } |
| 22 | 43 | | public void SetMessage(string message) { text.text = message; } |
| 22 | 44 | | public void SetPercentage(float percentage) { loadingBar.transform.localScale = new Vector3(percentage, 1, 1); } |
| 22 | 45 | | public void SetWalletPrompt(bool showWalletPrompt) { walletPrompt.gameObject.SetActive(showWalletPrompt); } |
| | 46 | | public void SetTips(bool showTips) |
| | 47 | | { |
| 12 | 48 | | tipsContainer.gameObject.SetActive(showTips); |
| 12 | 49 | | noTipsContainer.gameObject.SetActive(!showTips); |
| 12 | 50 | | } |
| | 51 | |
|
| 18 | 52 | | private void OnDestroy() { isDestroyed = true; } |
| | 53 | |
|
| | 54 | | public void Dispose() |
| | 55 | | { |
| 1 | 56 | | if (isDestroyed) |
| 0 | 57 | | return; |
| 1 | 58 | | isDestroyed = true; |
| 1 | 59 | | Destroy(gameObject); |
| 1 | 60 | | } |
| | 61 | | } |
| | 62 | | } |