| | 1 | | using DCL.Helpers; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL.Components |
| | 5 | | { |
| | 6 | | public class LoadWrapper_OBJ : LoadWrapper |
| | 7 | | { |
| | 8 | | DynamicOBJLoaderController objLoaderComponent; |
| | 9 | | System.Action<LoadWrapper> OnSuccessEvent; |
| | 10 | |
|
| | 11 | | public override void Unload() |
| | 12 | | { |
| 1 | 13 | | objLoaderComponent.OnFinishedLoadingAsset -= SuccessWrapper; |
| 1 | 14 | | Object.Destroy(objLoaderComponent); |
| 1 | 15 | | entity.Cleanup(); |
| 1 | 16 | | } |
| | 17 | |
|
| | 18 | | public override void Load(string src, System.Action<LoadWrapper> OnSuccess, System.Action<LoadWrapper> OnFail) |
| | 19 | | { |
| 1 | 20 | | if (string.IsNullOrEmpty(src)) |
| 0 | 21 | | return; |
| | 22 | |
|
| 1 | 23 | | if (objLoaderComponent == null) |
| 1 | 24 | | objLoaderComponent = entity.meshRootGameObject.GetOrCreateComponent<DynamicOBJLoaderController>(); |
| | 25 | |
|
| 1 | 26 | | objLoaderComponent.OnFinishedLoadingAsset += SuccessWrapper; |
| 1 | 27 | | OnSuccessEvent = OnSuccess; |
| | 28 | |
|
| 1 | 29 | | alreadyLoaded = false; |
| 1 | 30 | | objLoaderComponent.LoadAsset(src, true); |
| | 31 | |
|
| 1 | 32 | | if (objLoaderComponent.loadingPlaceholder == null) |
| | 33 | | { |
| 1 | 34 | | objLoaderComponent.loadingPlaceholder = |
| | 35 | | Helpers.Utils.AttachPlaceholderRendererGameObject(entity.gameObject.transform); |
| 1 | 36 | | } |
| | 37 | | else |
| | 38 | | { |
| 0 | 39 | | objLoaderComponent.loadingPlaceholder.SetActive(true); |
| | 40 | | } |
| 0 | 41 | | } |
| | 42 | |
|
| | 43 | | void SuccessWrapper() |
| | 44 | | { |
| 1 | 45 | | CallOnComponentUpdated(); |
| 1 | 46 | | OnSuccessEvent?.Invoke(this); |
| 1 | 47 | | } |
| | 48 | |
|
| | 49 | | void CallOnComponentUpdated() |
| | 50 | | { |
| 1 | 51 | | alreadyLoaded = true; |
| | 52 | |
|
| 1 | 53 | | if (entity.OnShapeUpdated != null) |
| | 54 | | { |
| 1 | 55 | | entity.OnShapeUpdated.Invoke(entity); |
| | 56 | | } |
| 1 | 57 | | entity.OnShapeLoaded?.Invoke(entity); |
| | 58 | |
|
| 1 | 59 | | CollidersManager.i.ConfigureColliders(entity); |
| 1 | 60 | | } |
| | 61 | |
|
| | 62 | | } |
| | 63 | | } |