| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL; |
| | 3 | | using DCL.LoadingScreen; |
| | 4 | | using DCL.Providers; |
| | 5 | | using MainScripts.DCL.Controllers.ShaderPrewarm; |
| | 6 | | using System.Threading; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace DCLPlugins.LoadingScreenPlugin |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Plugin controller for the decoupled Loading Screen |
| | 13 | | /// </summary> |
| | 14 | | public class LoadingScreenPlugin : IPlugin |
| | 15 | | { |
| | 16 | | private const string LOADING_SCREEN_ASSET = "_LoadingScreen"; |
| | 17 | |
|
| | 18 | | private readonly DataStoreRef<DataStore_LoadingScreen> dataStoreLoadingScreen; |
| | 19 | | private readonly CancellationTokenSource cancellationTokenSource; |
| | 20 | |
|
| | 21 | | private LoadingScreenController loadingScreenController; |
| | 22 | |
|
| 0 | 23 | | public LoadingScreenPlugin() |
| | 24 | | { |
| 0 | 25 | | dataStoreLoadingScreen.Ref.decoupledLoadingHUD.visible.Set(true); |
| | 26 | |
|
| 0 | 27 | | cancellationTokenSource = new CancellationTokenSource(); |
| 0 | 28 | | CreateLoadingScreen(cancellationTokenSource.Token).Forget(); |
| 0 | 29 | | } |
| | 30 | |
|
| | 31 | | private async UniTaskVoid CreateLoadingScreen(CancellationToken cancellationToken = default) |
| | 32 | | { |
| 0 | 33 | | loadingScreenController = new LoadingScreenController( |
| | 34 | | CreateLoadingScreenView(), |
| | 35 | | Environment.i.world.sceneController, Environment.i.world.state, NotificationsController.i, |
| | 36 | | DataStore.i.player, DataStore.i.common, dataStoreLoadingScreen.Ref, DataStore.i.realm, new ShaderPrewarm |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | public void Dispose() |
| | 40 | | { |
| 0 | 41 | | cancellationTokenSource.Cancel(); |
| 0 | 42 | | cancellationTokenSource.Dispose(); |
| | 43 | |
|
| 0 | 44 | | loadingScreenController.Dispose(); |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | public static LoadingScreenView CreateLoadingScreenView() => |
| 0 | 48 | | GameObject.Instantiate(Resources.Load<GameObject>(LOADING_SCREEN_ASSET)).GetComponent<LoadingScreenView>(); |
| | 49 | | } |
| | 50 | | } |