| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public interface IPublishPopupView |
| | 6 | | { |
| | 7 | | public float currentProgress { get; } |
| | 8 | |
|
| | 9 | | void PublishStart(); |
| | 10 | | void PublishEnd(bool isOk, string message); |
| | 11 | | void SetPercentage(float newValue); |
| | 12 | | } |
| | 13 | |
|
| | 14 | | public class PublishPopupView : MonoBehaviour, IPublishPopupView |
| | 15 | | { |
| | 16 | | internal const string VIEW_PATH = "Common/PublishPopupView"; |
| | 17 | | internal const string TITLE_INITIAL_MESSAGE = "Publishing Scene..."; |
| | 18 | | internal const string SUCCESS_TITLE_MESSAGE = "Scene Published!"; |
| | 19 | | internal const string FAIL_TITLE_MESSAGE = "Whoops!"; |
| | 20 | | internal const string SUCCESS_MESSAGE = "We successfully publish your scene."; |
| | 21 | | internal const string FAIL_MESSAGE = "There has been an unexpected error. Please contact the support service on the |
| | 22 | |
|
| 0 | 23 | | public float currentProgress => loadingBar.currentPercentage; |
| | 24 | |
|
| | 25 | | [SerializeField] internal TMP_Text titleText; |
| | 26 | | [SerializeField] internal TMP_Text resultText; |
| | 27 | | [SerializeField] internal TMP_Text errorDetailsText; |
| | 28 | | [SerializeField] internal LoadingBar loadingBar; |
| | 29 | | [SerializeField] internal Button closeButton; |
| | 30 | |
|
| | 31 | | internal static PublishPopupView Create() |
| | 32 | | { |
| 3 | 33 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<PublishPopupView>(); |
| 3 | 34 | | view.gameObject.name = "_PublishPopupView"; |
| | 35 | |
|
| 3 | 36 | | return view; |
| | 37 | | } |
| | 38 | |
|
| 6 | 39 | | private void Awake() { closeButton.onClick.AddListener(CloseModal); } |
| | 40 | |
|
| 6 | 41 | | private void OnDestroy() { closeButton.onClick.RemoveListener(CloseModal); } |
| | 42 | |
|
| 8 | 43 | | private void OnEnable() { AudioScriptableObjects.dialogOpen.Play(); } |
| | 44 | |
|
| 8 | 45 | | private void OnDisable() { AudioScriptableObjects.dialogClose.Play(); } |
| | 46 | |
|
| | 47 | | public void PublishStart() |
| | 48 | | { |
| 1 | 49 | | gameObject.SetActive(true); |
| 1 | 50 | | loadingBar.SetActive(true); |
| 1 | 51 | | resultText.gameObject.SetActive(false); |
| 1 | 52 | | closeButton.gameObject.SetActive(false); |
| 1 | 53 | | errorDetailsText.gameObject.SetActive(false); |
| 1 | 54 | | titleText.text = TITLE_INITIAL_MESSAGE; |
| | 55 | |
|
| 1 | 56 | | AudioScriptableObjects.enable.Play(); |
| 1 | 57 | | } |
| | 58 | |
|
| | 59 | | public void PublishEnd(bool isOk, string message) |
| | 60 | | { |
| 2 | 61 | | loadingBar.SetActive(false); |
| 2 | 62 | | titleText.text = isOk ? SUCCESS_TITLE_MESSAGE : FAIL_TITLE_MESSAGE; |
| 2 | 63 | | resultText.text = isOk ? SUCCESS_MESSAGE : FAIL_MESSAGE; |
| 2 | 64 | | errorDetailsText.gameObject.SetActive(!isOk); |
| 2 | 65 | | errorDetailsText.text = isOk ? "" : message; |
| 2 | 66 | | resultText.gameObject.SetActive(true); |
| 2 | 67 | | closeButton.gameObject.SetActive(true); |
| 2 | 68 | | } |
| | 69 | |
|
| 0 | 70 | | public void SetPercentage(float newValue) { loadingBar.SetPercentage(newValue); } |
| | 71 | |
|
| 0 | 72 | | private void CloseModal() { gameObject.SetActive(false); } |
| | 73 | | } |