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