| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.Builder |
| | 7 | | { |
| | 8 | | public interface IPublishProgressController |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Fired when the user confirm the deployment |
| | 12 | | /// </summary> |
| | 13 | | event Action OnConfirm; |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// The back button has been pressed |
| | 17 | | /// </summary> |
| | 18 | | event Action OnBackPressed; |
| | 19 | |
|
| | 20 | | void Initialize(); |
| | 21 | |
|
| | 22 | | void Dispose(); |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// This will show the confirmation pop up |
| | 26 | | /// </summary> |
| | 27 | | void ShowConfirmDeploy(); |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// This is called when the deployment has succeed |
| | 31 | | /// </summary> |
| | 32 | | /// <param name="publishedScene"></param> |
| | 33 | | void DeploySuccess(); |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Set the scene to publish |
| | 37 | | /// </summary> |
| | 38 | | /// <param name="scene"></param> |
| | 39 | | void SetInfoToPublish(IBuilderScene scene, PublishInfo info); |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// This is called when the deployment has failed with the error as parameter |
| | 43 | | /// </summary> |
| | 44 | | /// <param name="error"></param> |
| | 45 | | void DeployError(string error); |
| | 46 | | } |
| | 47 | |
|
| | 48 | | public class PublishProgressController : IPublishProgressController |
| | 49 | | { |
| | 50 | | public event Action OnConfirm; |
| | 51 | | public event Action OnBackPressed; |
| | 52 | |
|
| | 53 | | private const string PROGRESS_PREFAB_PATH = "PublishProgressView"; |
| | 54 | |
|
| | 55 | | internal IPublishProgressView view; |
| | 56 | |
|
| | 57 | | public void Initialize() |
| | 58 | | { |
| 0 | 59 | | view = GameObject.Instantiate(Resources.Load<PublishProgressView>(PROGRESS_PREFAB_PATH)); |
| | 60 | |
|
| 0 | 61 | | view.OnViewClosed += ViewClosed; |
| 0 | 62 | | view.OnBackPressed += BackPressed; |
| 0 | 63 | | view.OnPublishConfirmButtonPressed += ConfirmPressed; |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | public void Dispose() |
| | 67 | | { |
| 0 | 68 | | view.OnViewClosed -= ViewClosed; |
| 0 | 69 | | view.OnBackPressed -= BackPressed; |
| 0 | 70 | | view.OnPublishConfirmButtonPressed -= ConfirmPressed; |
| | 71 | |
|
| 0 | 72 | | view.Dispose(); |
| 0 | 73 | | } |
| | 74 | |
|
| | 75 | | private void BackPressed() |
| | 76 | | { |
| 0 | 77 | | OnBackPressed?.Invoke(); |
| 0 | 78 | | } |
| | 79 | |
|
| 0 | 80 | | public void ShowConfirmDeploy() { view.ConfirmDeployment(); } |
| | 81 | |
|
| | 82 | | private void ConfirmPressed() |
| | 83 | | { |
| 0 | 84 | | OnConfirm?.Invoke(); |
| 0 | 85 | | view.PublishStarted(); |
| 0 | 86 | | } |
| | 87 | |
|
| 0 | 88 | | public void DeploySuccess() { view.ProjectPublished(); } |
| | 89 | |
|
| 0 | 90 | | public void SetInfoToPublish(IBuilderScene scene, PublishInfo info) { view.SetPublishInfo(scene, info); } |
| | 91 | |
|
| 0 | 92 | | public void DeployError(string error) { view.PublishError(error); } |
| | 93 | |
|
| 0 | 94 | | private void ViewClosed() { view.Hide(); } |
| | 95 | | } |
| | 96 | | } |