| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.Components |
| | 7 | | { |
| | 8 | | public class NFTShape : LoadableShape<LoadWrapper_NFT, NFTShape.Model> |
| | 9 | | { |
| | 10 | | [System.Serializable] |
| | 11 | | public new class Model : LoadableShape.Model |
| | 12 | | { |
| 19 | 13 | | public Color color = new Color(0.6404918f, 0.611472f, 0.8584906f); // "light purple" default, same as in exp |
| | 14 | | public int style = 0; |
| | 15 | |
|
| 6 | 16 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); } |
| | 17 | | } |
| | 18 | |
|
| 3 | 19 | | public override string componentName => "NFT Shape"; |
| | 20 | |
|
| 15 | 21 | | public NFTShape() { model = new Model(); } |
| | 22 | |
|
| 9 | 23 | | public override int GetClassId() { return (int) CLASS_ID.NFT_SHAPE; } |
| | 24 | |
|
| | 25 | | protected override void AttachShape(IDCLEntity entity) |
| | 26 | | { |
| 3 | 27 | | if (string.IsNullOrEmpty(model.src)) |
| | 28 | | { |
| | 29 | | #if UNITY_EDITOR |
| 0 | 30 | | Debug.LogError($"NFT SHAPE with url '{model.src}' couldn't be loaded."); |
| | 31 | | #endif |
| 0 | 32 | | return; |
| | 33 | | } |
| | 34 | |
|
| 3 | 35 | | entity.meshesInfo.meshRootGameObject = NFTShapeFactory.InstantiateLoaderController(model.style); |
| 3 | 36 | | entity.meshesInfo.currentShape = this; |
| | 37 | |
|
| 3 | 38 | | entity.meshRootGameObject.name = componentName + " mesh"; |
| 3 | 39 | | entity.meshRootGameObject.transform.SetParent(entity.gameObject.transform); |
| 3 | 40 | | entity.meshRootGameObject.transform.ResetLocalTRS(); |
| | 41 | |
|
| 3 | 42 | | entity.OnShapeUpdated += UpdateBackgroundColor; |
| | 43 | |
|
| 3 | 44 | | var loadableShape = GetOrAddLoaderForEntity<LoadWrapper_NFT>(entity); |
| | 45 | |
|
| 3 | 46 | | loadableShape.entity = entity; |
| 3 | 47 | | loadableShape.initialVisibility = model.visible; |
| | 48 | |
|
| 3 | 49 | | loadableShape.withCollisions = model.withCollisions; |
| 3 | 50 | | loadableShape.backgroundColor = model.color; |
| | 51 | |
|
| 3 | 52 | | loadableShape.Load(model.src, OnLoadCompleted, OnLoadFailed); |
| 3 | 53 | | } |
| | 54 | |
|
| | 55 | | protected override void DetachShape(IDCLEntity entity) |
| | 56 | | { |
| 0 | 57 | | if (entity == null || entity.meshRootGameObject == null) |
| 0 | 58 | | return; |
| | 59 | |
|
| 0 | 60 | | entity.OnShapeUpdated -= UpdateBackgroundColor; |
| | 61 | |
|
| 0 | 62 | | base.DetachShape(entity); |
| 0 | 63 | | } |
| | 64 | |
|
| 6 | 65 | | protected override void ConfigureColliders(IDCLEntity entity) { CollidersManager.i.ConfigureColliders(entity.mes |
| | 66 | |
|
| | 67 | | void UpdateBackgroundColor(IDCLEntity entity) |
| | 68 | | { |
| 4 | 69 | | if (previousModel is NFTShape.Model && model.color == previousModel.color) |
| 1 | 70 | | return; |
| | 71 | |
|
| 3 | 72 | | var loadableShape = GetLoaderForEntity(entity) as LoadWrapper_NFT; |
| 3 | 73 | | loadableShape?.loaderController.UpdateBackgroundColor(model.color); |
| 3 | 74 | | } |
| | 75 | |
|
| | 76 | | public override string ToString() |
| | 77 | | { |
| 0 | 78 | | if (model == null) |
| 0 | 79 | | return base.ToString(); |
| | 80 | |
|
| 0 | 81 | | return $"{componentName} (src = {model.src})"; |
| | 82 | | } |
| | 83 | | } |
| | 84 | | } |