| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | public interface ITagComponentView |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// Set the tag text. |
| | 9 | | /// </summary> |
| | 10 | | /// <param name="newText">New text.</param> |
| | 11 | | void SetText(string newText); |
| | 12 | |
|
| | 13 | | /// <summary> |
| | 14 | | /// Set the tag icon. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="newIcon">New Icon. Null for hide the icon.</param> |
| | 17 | | void SetIcon(Sprite newIcon); |
| | 18 | | } |
| | 19 | |
|
| | 20 | | public class TagComponentView : BaseComponentView, ITagComponentView, IComponentModelConfig |
| | 21 | | { |
| | 22 | | [Header("Prefab References")] |
| | 23 | | [SerializeField] internal Image icon; |
| | 24 | | [SerializeField] internal TMP_Text text; |
| | 25 | |
|
| | 26 | | [Header("Configuration")] |
| | 27 | | [SerializeField] internal TagComponentModel model; |
| | 28 | |
|
| | 29 | | public void Configure(BaseComponentModel newModel) |
| | 30 | | { |
| 1 | 31 | | model = (TagComponentModel)newModel; |
| 1 | 32 | | RefreshControl(); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | public override void RefreshControl() |
| | 36 | | { |
| 1 | 37 | | if (model == null) |
| 0 | 38 | | return; |
| | 39 | |
|
| 1 | 40 | | SetText(model.text); |
| 1 | 41 | | SetIcon(model.icon); |
| 1 | 42 | | } |
| | 43 | |
|
| | 44 | | public void SetText(string newText) |
| | 45 | | { |
| 21 | 46 | | model.text = newText; |
| | 47 | |
|
| 21 | 48 | | if (text == null) |
| 0 | 49 | | return; |
| | 50 | |
|
| 21 | 51 | | text.text = newText; |
| 21 | 52 | | } |
| | 53 | |
|
| | 54 | | public void SetIcon(Sprite newIcon) |
| | 55 | | { |
| 3 | 56 | | model.icon = newIcon; |
| | 57 | |
|
| 3 | 58 | | if (icon == null) |
| 0 | 59 | | return; |
| | 60 | |
|
| 3 | 61 | | icon.enabled = newIcon != null; |
| 3 | 62 | | icon.sprite = newIcon; |
| 3 | 63 | | } |
| | 64 | | } |