| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.Assertions; |
| | 4 | |
|
| | 5 | | namespace DCL.Components |
| | 6 | | { |
| | 7 | |
|
| | 8 | | public class LoadWrapper_GLTF : LoadWrapper |
| | 9 | | { |
| | 10 | | static readonly bool VERBOSE = false; |
| | 11 | | RendereableAssetLoadHelper loadHelper; |
| | 12 | | public ContentProvider customContentProvider; |
| | 13 | |
|
| | 14 | | public override void Load(string targetUrl, Action<LoadWrapper> OnSuccess, Action<LoadWrapper> OnFail) |
| | 15 | | { |
| 78 | 16 | | if (loadHelper != null) |
| | 17 | | { |
| 2 | 18 | | loadHelper.Unload(); |
| | 19 | |
|
| 2 | 20 | | if (VERBOSE) |
| 0 | 21 | | Debug.Log("Forgetting not null loader..."); |
| | 22 | | } |
| | 23 | |
|
| 78 | 24 | | alreadyLoaded = false; |
| 78 | 25 | | Assert.IsFalse(string.IsNullOrEmpty(targetUrl), "url is null!!"); |
| | 26 | |
|
| | 27 | |
|
| 78 | 28 | | if (customContentProvider == null) |
| 0 | 29 | | loadHelper = new RendereableAssetLoadHelper(this.entity.scene.contentProvider, entity.scene.sceneData.ba |
| | 30 | | else |
| 78 | 31 | | loadHelper = new RendereableAssetLoadHelper(customContentProvider, entity.scene.sceneData.baseUrlBundles |
| | 32 | |
|
| | 33 | |
|
| 78 | 34 | | loadHelper.settings.parent = entity.meshRootGameObject.transform; |
| | 35 | |
|
| 78 | 36 | | if (initialVisibility == false) |
| | 37 | | { |
| 0 | 38 | | loadHelper.settings.visibleFlags = AssetPromiseSettings_Rendering.VisibleFlags.INVISIBLE; |
| 0 | 39 | | } |
| | 40 | | else |
| | 41 | | { |
| 78 | 42 | | if (useVisualFeedback) |
| 1 | 43 | | loadHelper.settings.visibleFlags = AssetPromiseSettings_Rendering.VisibleFlags.VISIBLE_WITH_TRANSITI |
| | 44 | | else |
| 77 | 45 | | loadHelper.settings.visibleFlags = AssetPromiseSettings_Rendering.VisibleFlags.VISIBLE_WITHOUT_TRANS |
| | 46 | | } |
| | 47 | |
|
| 78 | 48 | | this.entity.OnCleanupEvent -= OnEntityCleanup; |
| 78 | 49 | | this.entity.OnCleanupEvent += OnEntityCleanup; |
| | 50 | |
|
| 134 | 51 | | loadHelper.OnSuccessEvent += (x) => OnSuccessWrapper(OnSuccess); |
| 81 | 52 | | loadHelper.OnFailEvent += () => OnFailWrapper(OnFail); |
| 78 | 53 | | loadHelper.Load(targetUrl); |
| 78 | 54 | | } |
| | 55 | |
|
| | 56 | | private void OnFailWrapper(Action<LoadWrapper> OnFail) |
| | 57 | | { |
| 3 | 58 | | alreadyLoaded = true; |
| 3 | 59 | | this.entity.OnCleanupEvent -= OnEntityCleanup; |
| 3 | 60 | | OnFail?.Invoke(this); |
| 3 | 61 | | } |
| | 62 | |
|
| | 63 | | private void OnSuccessWrapper(Action<LoadWrapper> OnSuccess) |
| | 64 | | { |
| 56 | 65 | | alreadyLoaded = true; |
| 56 | 66 | | OnSuccess?.Invoke(this); |
| 56 | 67 | | } |
| | 68 | |
|
| 2 | 69 | | public void OnEntityCleanup(ICleanableEventDispatcher source) { Unload(); } |
| | 70 | |
|
| | 71 | | public override void Unload() |
| | 72 | | { |
| 70 | 73 | | loadHelper.Unload(); |
| 70 | 74 | | this.entity.OnCleanupEvent -= OnEntityCleanup; |
| 70 | 75 | | } |
| | 76 | |
|
| 0 | 77 | | public override string ToString() { return $"LoadWrapper ... {loadHelper.ToString()}"; } |
| | 78 | | } |
| | 79 | | } |