| | 1 | | using DCL.Helpers; |
| | 2 | | using DCL.Models; |
| | 3 | | using System.Collections; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | | using Decentraland.Sdk.Ecs6; |
| | 7 | | using MainScripts.DCL.Components; |
| | 8 | |
|
| | 9 | | namespace DCL.Components |
| | 10 | | { |
| | 11 | | public class UIContainerRect : UIShape<UIContainerRectReferencesContainer, UIContainerRect.Model> |
| | 12 | | { |
| | 13 | | [System.Serializable] |
| | 14 | | public new class Model : UIShape.Model |
| | 15 | | { |
| | 16 | | public float thickness; |
| 157 | 17 | | public Color color = Color.clear; |
| | 18 | |
|
| | 19 | | public override BaseModel GetDataFromJSON(string json) => |
| 61 | 20 | | Utils.SafeFromJson<Model>(json); |
| | 21 | |
|
| | 22 | | public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel) |
| | 23 | | { |
| 0 | 24 | | if (pbModel.PayloadCase != ComponentBodyPayload.PayloadOneofCase.UiContainerRect) |
| 0 | 25 | | return Utils.SafeUnimplemented<UIContainerRect, Model>(expected: ComponentBodyPayload.PayloadOneofCa |
| | 26 | |
|
| 0 | 27 | | var pb = new Model(); |
| 0 | 28 | | if (pbModel.UiContainerRect.HasName) pb.name = pbModel.UiContainerRect.Name; |
| 0 | 29 | | if (pbModel.UiContainerRect.HasParentComponent) pb.parentComponent = pbModel.UiContainerRect.ParentCompo |
| 0 | 30 | | if (pbModel.UiContainerRect.HasVisible) pb.visible = pbModel.UiContainerRect.Visible; |
| 0 | 31 | | if (pbModel.UiContainerRect.HasOpacity) pb.opacity = pbModel.UiContainerRect.Opacity; |
| 0 | 32 | | if (pbModel.UiContainerRect.HasHAlign) pb.hAlign = pbModel.UiContainerRect.HAlign; |
| 0 | 33 | | if (pbModel.UiContainerRect.HasVAlign) pb.vAlign = pbModel.UiContainerRect.VAlign; |
| 0 | 34 | | if (pbModel.UiContainerRect.Width != null) pb.width = SDK6DataMapExtensions.FromProtobuf(pb.width, pbMod |
| 0 | 35 | | if (pbModel.UiContainerRect.Height != null) pb.height = SDK6DataMapExtensions.FromProtobuf(pb.height, pb |
| 0 | 36 | | if (pbModel.UiContainerRect.PositionX != null) pb.positionX = SDK6DataMapExtensions.FromProtobuf(pb.posi |
| 0 | 37 | | if (pbModel.UiContainerRect.PositionY != null) pb.positionY = SDK6DataMapExtensions.FromProtobuf(pb.posi |
| 0 | 38 | | if (pbModel.UiContainerRect.HasIsPointerBlocker) pb.isPointerBlocker = pbModel.UiContainerRect.IsPointer |
| | 39 | |
|
| 0 | 40 | | if (pbModel.UiContainerRect.Color != null) pb.color = pbModel.UiContainerRect.Color.AsUnityColor(); |
| 0 | 41 | | if (pbModel.UiContainerRect.HasThickness) pb.thickness = pbModel.UiContainerRect.Thickness; |
| | 42 | |
|
| 0 | 43 | | return pb; |
| | 44 | | } |
| | 45 | | } |
| | 46 | |
|
| 33 | 47 | | public override string referencesContainerPrefabName => "UIContainerRect"; |
| | 48 | |
|
| 99 | 49 | | public UIContainerRect() { model = new Model(); } |
| | 50 | |
|
| 0 | 51 | | public override int GetClassId() { return (int) CLASS_ID.UI_CONTAINER_RECT; } |
| | 52 | |
|
| | 53 | | public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null) |
| | 54 | | { |
| 0 | 55 | | Debug.LogError( |
| | 56 | | "Aborted UIContainerRectShape attachment to an entity. UIShapes shouldn't be attached to entities."); |
| 0 | 57 | | } |
| | 58 | |
|
| 0 | 59 | | public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null) { } |
| | 60 | |
|
| | 61 | | public override IEnumerator ApplyChanges(BaseModel newModel) |
| | 62 | | { |
| 62 | 63 | | referencesContainer.image.color = new Color(model.color.r, model.color.g, model.color.b, model.color.a); |
| 62 | 64 | | referencesContainer.image.raycastTarget = model.color.a >= RAYCAST_ALPHA_THRESHOLD; |
| | 65 | |
|
| 62 | 66 | | Outline outline = referencesContainer.image.GetComponent<Outline>(); |
| | 67 | |
|
| 62 | 68 | | if (model.thickness > 0f) |
| | 69 | | { |
| 3 | 70 | | if (outline == null) |
| | 71 | | { |
| 3 | 72 | | outline = referencesContainer.image.gameObject.AddComponent<Outline>(); |
| | 73 | | } |
| | 74 | |
|
| 3 | 75 | | outline.effectDistance = new Vector2(model.thickness, model.thickness); |
| | 76 | | } |
| 59 | 77 | | else if (outline != null) |
| | 78 | | { |
| 1 | 79 | | Object.DestroyImmediate(outline, false); |
| | 80 | | } |
| | 81 | |
|
| 62 | 82 | | return null; |
| | 83 | | } |
| | 84 | |
|
| | 85 | | public override void Dispose() |
| | 86 | | { |
| 1 | 87 | | if (referencesContainer != null) |
| 1 | 88 | | Utils.SafeDestroy(referencesContainer.gameObject); |
| | 89 | |
|
| 1 | 90 | | base.Dispose(); |
| 1 | 91 | | } |
| | 92 | | } |
| | 93 | | } |