| | 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 | |
|
| 61 | 19 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); } |
| | 20 | | } |
| | 21 | |
|
| 33 | 22 | | public override string referencesContainerPrefabName => "UIContainerRect"; |
| | 23 | |
|
| 99 | 24 | | public UIContainerRect() { model = new Model(); } |
| | 25 | |
|
| 0 | 26 | | public override int GetClassId() { return (int) CLASS_ID.UI_CONTAINER_RECT; } |
| | 27 | |
|
| | 28 | | public override void AttachTo(IDCLEntity entity, System.Type overridenAttachedType = null) |
| | 29 | | { |
| 0 | 30 | | Debug.LogError( |
| | 31 | | "Aborted UIContainerRectShape attachment to an entity. UIShapes shouldn't be attached to entities."); |
| 0 | 32 | | } |
| | 33 | |
|
| 0 | 34 | | public override void DetachFrom(IDCLEntity entity, System.Type overridenAttachedType = null) { } |
| | 35 | |
|
| | 36 | | public override IEnumerator ApplyChanges(BaseModel newModel) |
| | 37 | | { |
| 62 | 38 | | referencesContainer.image.color = new Color(model.color.r, model.color.g, model.color.b, model.color.a); |
| 62 | 39 | | referencesContainer.image.raycastTarget = model.color.a >= RAYCAST_ALPHA_THRESHOLD; |
| | 40 | |
|
| 62 | 41 | | Outline outline = referencesContainer.image.GetComponent<Outline>(); |
| | 42 | |
|
| 62 | 43 | | if (model.thickness > 0f) |
| | 44 | | { |
| 3 | 45 | | if (outline == null) |
| | 46 | | { |
| 3 | 47 | | outline = referencesContainer.image.gameObject.AddComponent<Outline>(); |
| | 48 | | } |
| | 49 | |
|
| 3 | 50 | | outline.effectDistance = new Vector2(model.thickness, model.thickness); |
| 3 | 51 | | } |
| 59 | 52 | | else if (outline != null) |
| | 53 | | { |
| 1 | 54 | | Object.DestroyImmediate(outline, false); |
| | 55 | | } |
| | 56 | |
|
| 62 | 57 | | return null; |
| | 58 | | } |
| | 59 | |
|
| | 60 | | public override void Dispose() |
| | 61 | | { |
| 1 | 62 | | if (referencesContainer != null) |
| 1 | 63 | | Utils.SafeDestroy(referencesContainer.gameObject); |
| | 64 | |
|
| 1 | 65 | | base.Dispose(); |
| 1 | 66 | | } |
| | 67 | | } |
| | 68 | | } |