| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Builder; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | public interface IBuilderInWorldLoadingController |
| | 7 | | { |
| | 8 | | bool isActive { get; } |
| | 9 | |
|
| | 10 | | void Initialize(); |
| | 11 | | void Dispose(); |
| | 12 | | void Show(); |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// This will change the way the builder is loaded, this should be called before show or hide to work properly |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="sceneType"></param> |
| | 18 | | void SetLoadingType(ISceneManager.SceneType sceneType); |
| | 19 | |
|
| | 20 | | void Hide(bool forzeHidding = false, Action onHideAction = null); |
| | 21 | | void SetPercentage(float newValue); |
| | 22 | | } |
| | 23 | |
|
| | 24 | | public class BuilderInWorldLoadingController : IBuilderInWorldLoadingController |
| | 25 | | { |
| 0 | 26 | | public bool isActive => initialLoadingView != null && initialLoadingView.isActive; |
| | 27 | |
|
| | 28 | | internal IBuilderInWorldLoadingView initialLoadingView; |
| | 29 | |
|
| | 30 | | private const string VIEW_PATH = "BuilderInWorldLoadingView"; |
| 0 | 31 | | private ISceneManager.SceneType sceneType = ISceneManager.SceneType.DEPLOYED; |
| | 32 | |
|
| 28 | 33 | | public void Initialize() { AssignMainView(CreateView()); } |
| | 34 | |
|
| 6 | 35 | | public void Initialize(IBuilderInWorldLoadingView view) { AssignMainView(view); } |
| | 36 | |
|
| | 37 | | internal void AssignMainView(IBuilderInWorldLoadingView view) |
| | 38 | | { |
| 17 | 39 | | initialLoadingView = view; |
| | 40 | |
|
| 17 | 41 | | if (initialLoadingView.gameObject != null) |
| 14 | 42 | | initialLoadingView.gameObject.SetActive(false); |
| 17 | 43 | | } |
| | 44 | |
|
| | 45 | | private IBuilderInWorldLoadingView CreateView() |
| | 46 | | { |
| 14 | 47 | | var view = UnityEngine.Object.Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<IBuilderInWorldLoa |
| 14 | 48 | | view.gameObject.name = "_BuildModeLoadingHUD"; |
| | 49 | |
|
| 14 | 50 | | return view; |
| | 51 | | } |
| | 52 | |
|
| | 53 | | public void Dispose() |
| | 54 | | { |
| 17 | 55 | | if ( initialLoadingView == null || initialLoadingView.gameObject == null ) |
| 3 | 56 | | return; |
| | 57 | |
|
| 14 | 58 | | initialLoadingView.Dispose(); |
| 14 | 59 | | UnityEngine.Object.Destroy(initialLoadingView.gameObject); |
| 14 | 60 | | } |
| | 61 | |
|
| | 62 | | public void Show() |
| | 63 | | { |
| 1 | 64 | | if(sceneType == ISceneManager.SceneType.PROJECT) |
| 0 | 65 | | DataStore.i.HUDs.loadingHUD.visible.Set(true); |
| | 66 | | else |
| 1 | 67 | | initialLoadingView.Show(); |
| 1 | 68 | | } |
| | 69 | |
|
| | 70 | | public void SetLoadingType(ISceneManager.SceneType sceneType) |
| | 71 | | { |
| 0 | 72 | | this.sceneType = sceneType; |
| 0 | 73 | | } |
| | 74 | |
|
| | 75 | | public void Hide(bool forzeHidding = false, Action onHideAction = null) |
| | 76 | | { |
| 1 | 77 | | if (sceneType == ISceneManager.SceneType.PROJECT) |
| | 78 | | { |
| 0 | 79 | | DataStore.i.HUDs.loadingHUD.visible.Set(false); |
| 0 | 80 | | onHideAction?.Invoke(); |
| 0 | 81 | | } |
| | 82 | | else |
| | 83 | | { |
| 1 | 84 | | initialLoadingView.Hide(forzeHidding, onHideAction); |
| | 85 | | } |
| 1 | 86 | | } |
| | 87 | |
|
| | 88 | | public void SetPercentage(float newValue) |
| | 89 | | { |
| 1 | 90 | | if(sceneType == ISceneManager.SceneType.PROJECT) |
| 0 | 91 | | DataStore.i.HUDs.loadingHUD.percentage.Set(newValue); |
| | 92 | | else |
| 1 | 93 | | initialLoadingView.SetPercentage(newValue); |
| 1 | 94 | | } |
| | 95 | | } |