| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using System.Collections; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using Newtonsoft.Json; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace DCL.Components |
| | 10 | | { |
| | 11 | | public class UIText : UIShape<UITextReferencesContainer, UIText.Model> |
| | 12 | | { |
| | 13 | | [System.Serializable] |
| | 14 | | new public class Model : UIShape.Model |
| | 15 | | { |
| | 16 | | public TextShape.Model textModel; |
| | 17 | |
|
| 48 | 18 | | public Model() { textModel = new TextShape.Model(); } |
| | 19 | |
|
| | 20 | | public override BaseModel GetDataFromJSON(string json) |
| | 21 | | { |
| 4 | 22 | | Model model = Utils.SafeFromJson<Model>(json); |
| 4 | 23 | | textModel = (TextShape.Model) textModel.GetDataFromJSON(json); |
| 4 | 24 | | model.textModel = textModel; |
| 4 | 25 | | return model; |
| | 26 | | } |
| | 27 | | } |
| | 28 | |
|
| 4 | 29 | | public override string referencesContainerPrefabName => "UIText"; |
| | 30 | |
|
| 12 | 31 | | public UIText() { model = new Model(); } |
| | 32 | |
|
| 0 | 33 | | public override int GetClassId() { return (int) CLASS_ID.UI_TEXT_SHAPE; } |
| | 34 | |
|
| 0 | 35 | | public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null) { Debug.LogError("Abo |
| | 36 | |
|
| 0 | 37 | | public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null) { } |
| | 38 | |
|
| | 39 | | public override IEnumerator ApplyChanges(BaseModel newModel) |
| | 40 | | { |
| 8 | 41 | | model = (Model) newModel; |
| | 42 | |
|
| 8 | 43 | | yield return TextShape.ApplyModelChanges(scene, referencesContainer.text, model.textModel); |
| | 44 | |
|
| 8 | 45 | | RefreshAll(); |
| 8 | 46 | | } |
| | 47 | |
|
| | 48 | | protected override void RefreshDCLSize(RectTransform parentTransform = null) |
| | 49 | | { |
| 16 | 50 | | if (parentTransform == null) |
| | 51 | | { |
| 0 | 52 | | parentTransform = referencesContainer.GetComponentInParent<RectTransform>(); |
| | 53 | | } |
| | 54 | |
|
| 16 | 55 | | if (model.textModel.adaptWidth || model.textModel.adaptHeight) |
| 2 | 56 | | referencesContainer.text.ForceMeshUpdate(false); |
| | 57 | |
|
| 16 | 58 | | Bounds b = referencesContainer.text.textBounds; |
| | 59 | |
|
| | 60 | | float width, height; |
| | 61 | |
|
| 16 | 62 | | if (model.textModel.adaptWidth) |
| | 63 | | { |
| 2 | 64 | | width = b.size.x; |
| 2 | 65 | | } |
| | 66 | | else |
| | 67 | | { |
| 14 | 68 | | width = model.width.GetScaledValue(parentTransform.rect.width); |
| | 69 | | } |
| | 70 | |
|
| 16 | 71 | | if (model.textModel.adaptHeight) |
| | 72 | | { |
| 2 | 73 | | height = b.size.y; |
| 2 | 74 | | } |
| | 75 | | else |
| | 76 | | { |
| 14 | 77 | | height = model.height.GetScaledValue(parentTransform.rect.height); |
| | 78 | | } |
| | 79 | |
|
| 16 | 80 | | referencesContainer.layoutElementRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); |
| 16 | 81 | | referencesContainer.layoutElementRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); |
| 16 | 82 | | } |
| | 83 | |
|
| | 84 | | public override void Dispose() |
| | 85 | | { |
| 4 | 86 | | if (referencesContainer != null) |
| 4 | 87 | | Utils.SafeDestroy(referencesContainer.gameObject); |
| | 88 | |
|
| 4 | 89 | | base.Dispose(); |
| 4 | 90 | | } |
| | 91 | | } |
| | 92 | | } |