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