| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using System.Collections; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.UI; |
| | 8 | |
|
| | 9 | | namespace DCL.Components |
| | 10 | | { |
| | 11 | | public class UIContainerRect : UIShape<UIContainerRectReferencesContainer, UIContainerRect.Model> |
| | 12 | | { |
| | 13 | | [System.Serializable] |
| | 14 | | new public class Model : UIShape.Model |
| | 15 | | { |
| | 16 | | public float thickness = 0f; |
| 157 | 17 | | public Color color = Color.clear; |
| | 18 | | public bool adaptWidth = false; |
| | 19 | | public bool adaptHeight = false; |
| | 20 | |
|
| 61 | 21 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); } |
| | 22 | | } |
| | 23 | |
|
| 33 | 24 | | public override string referencesContainerPrefabName => "UIContainerRect"; |
| | 25 | |
|
| 99 | 26 | | public UIContainerRect() { model = new Model(); } |
| | 27 | |
|
| 0 | 28 | | public override int GetClassId() { return (int) CLASS_ID.UI_CONTAINER_RECT; } |
| | 29 | |
|
| | 30 | | public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null) |
| | 31 | | { |
| 0 | 32 | | Debug.LogError( |
| | 33 | | "Aborted UIContainerRectShape attachment to an entity. UIShapes shouldn't be attached to entities."); |
| 0 | 34 | | } |
| | 35 | |
|
| 0 | 36 | | public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null) { } |
| | 37 | |
|
| | 38 | | public override IEnumerator ApplyChanges(BaseModel newModel) |
| | 39 | | { |
| 62 | 40 | | referencesContainer.image.color = new Color(model.color.r, model.color.g, model.color.b, model.color.a); |
| 62 | 41 | | referencesContainer.image.raycastTarget = model.color.a >= RAYCAST_ALPHA_THRESHOLD; |
| | 42 | |
|
| 62 | 43 | | Outline outline = referencesContainer.image.GetComponent<Outline>(); |
| | 44 | |
|
| 62 | 45 | | if (model.thickness > 0f) |
| | 46 | | { |
| 3 | 47 | | if (outline == null) |
| | 48 | | { |
| 3 | 49 | | outline = referencesContainer.image.gameObject.AddComponent<Outline>(); |
| | 50 | | } |
| | 51 | |
|
| 3 | 52 | | outline.effectDistance = new Vector2(model.thickness, model.thickness); |
| 3 | 53 | | } |
| 59 | 54 | | else if (outline != null) |
| | 55 | | { |
| 1 | 56 | | Object.DestroyImmediate(outline, false); |
| | 57 | | } |
| | 58 | |
|
| 62 | 59 | | return null; |
| | 60 | | } |
| | 61 | |
|
| | 62 | | public override void Dispose() |
| | 63 | | { |
| 34 | 64 | | if (referencesContainer != null) |
| 25 | 65 | | Utils.SafeDestroy(referencesContainer.gameObject); |
| | 66 | |
|
| 34 | 67 | | base.Dispose(); |
| 34 | 68 | | } |
| | 69 | | } |
| | 70 | | } |