| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL.Providers; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Threading; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | namespace DCL.Controllers.LoadingScreenV2 |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// The LocalHintRequestSource class manages the retrieval of loading screen hints from a local JSON source. |
| | 12 | | /// </summary> |
| | 13 | | public class LocalHintRequestSource : IHintRequestSource |
| | 14 | | { |
| | 15 | | private const string LOCAL_HINTS_JSON_SOURCE = "LoadingScreenV2LocalHintsJsonSource"; |
| | 16 | |
|
| | 17 | | private readonly IAddressableResourceProvider addressablesProvider; |
| | 18 | |
|
| 0 | 19 | | public LocalHintRequestSource(string sourceAddressableSceneJson, SourceTag sourceTag, IAddressableResourceProvid |
| | 20 | | { |
| 0 | 21 | | Source = sourceAddressableSceneJson; |
| 0 | 22 | | this.SourceTag = sourceTag; |
| 0 | 23 | | LoadingHints = new List<Hint>(); |
| 0 | 24 | | this.addressablesProvider = addressablesProvider; |
| 0 | 25 | | } |
| | 26 | |
|
| 0 | 27 | | public string Source { get; } |
| 0 | 28 | | public SourceTag SourceTag { get; } |
| 0 | 29 | | public List<Hint> LoadingHints { get; private set; } |
| | 30 | |
|
| | 31 | | public UniTask<List<Hint>> GetHintsAsync(CancellationToken ctx) |
| | 32 | | { |
| | 33 | | // If cancellation is requested, return an empty list |
| 0 | 34 | | if (ctx.IsCancellationRequested) |
| 0 | 35 | | return UniTask.FromResult(new List<Hint>()); |
| | 36 | |
|
| | 37 | | // Otherwise, return hints when they are loaded from the addressable |
| 0 | 38 | | return LoadHintsFromAddressable(Source, ctx); |
| | 39 | | } |
| | 40 | |
|
| | 41 | | public void Dispose() |
| | 42 | | { |
| 0 | 43 | | LoadingHints.Clear(); |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | internal async UniTask<List<Hint>> LoadHintsFromAddressable(string addressableSourceKey, CancellationToken ctx) |
| | 47 | | { |
| | 48 | | try |
| | 49 | | { |
| 0 | 50 | | if (ctx.IsCancellationRequested) |
| 0 | 51 | | return LoadingHints; |
| | 52 | |
|
| 0 | 53 | | TextAsset containerSceneAddressable = await addressablesProvider.GetAddressable<TextAsset>(addressableSo |
| | 54 | |
|
| 0 | 55 | | if (containerSceneAddressable == null) { throw new Exception("Failed to load the addressable asset"); } |
| | 56 | |
|
| 0 | 57 | | LoadingHints = HintSceneParserUtil.ParseJsonToHints(containerSceneAddressable.text); |
| 0 | 58 | | return LoadingHints; |
| | 59 | | } |
| 0 | 60 | | catch (Exception ex) |
| | 61 | | { |
| 0 | 62 | | Debug.LogWarning($"Failed to load hints from addressable: {ex.Message}"); |
| | 63 | |
|
| 0 | 64 | | return LoadingHints; |
| | 65 | | } |
| 0 | 66 | | } |
| | 67 | | } |
| | 68 | | } |