| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public class MapParcelHighlight : MonoBehaviour |
| | 8 | | { |
| | 9 | | public enum HighlighStyle |
| | 10 | | { |
| | 11 | | DEFAULT = 0, |
| | 12 | | BUILDER_ENABLE = 1, |
| | 13 | | BUILDER_DISABLE = 2, |
| | 14 | | } |
| | 15 | |
|
| | 16 | | [Header("Builder in world style")] |
| | 17 | | [SerializeField] internal Sprite builderHighlightTexture; |
| | 18 | | [SerializeField] internal Sprite builderHighlightDisableTexture; |
| | 19 | |
|
| | 20 | | [Header("Default style")] |
| | 21 | | [SerializeField] internal Sprite defaultTexture; |
| | 22 | |
|
| | 23 | | [Header("Normal map style")] |
| | 24 | | [SerializeField] internal Image highlighImage; |
| | 25 | |
|
| | 26 | | private Vector2 highlighSize; |
| | 27 | | private RectTransform rectTransform; |
| | 28 | |
|
| | 29 | | private void Awake() |
| | 30 | | { |
| 0 | 31 | | rectTransform = GetComponent<RectTransform>(); |
| 0 | 32 | | } |
| | 33 | |
|
| | 34 | | public void SetStyle(HighlighStyle style) |
| | 35 | | { |
| | 36 | | switch (style) |
| | 37 | | { |
| | 38 | | case HighlighStyle.DEFAULT: |
| 0 | 39 | | highlighImage.sprite = defaultTexture; |
| 0 | 40 | | ChangeHighlighSize(Vector2Int.one); |
| 0 | 41 | | break; |
| | 42 | | case HighlighStyle.BUILDER_ENABLE: |
| 0 | 43 | | highlighImage.sprite = builderHighlightTexture; |
| 0 | 44 | | break; |
| | 45 | | case HighlighStyle.BUILDER_DISABLE: |
| 0 | 46 | | highlighImage.sprite = builderHighlightDisableTexture; |
| | 47 | | break; |
| | 48 | | } |
| 0 | 49 | | } |
| | 50 | |
|
| | 51 | | public void SetScale(float scale) |
| | 52 | | { |
| | 53 | | // This can happen if the set scale is set before the awake method |
| 12 | 54 | | if(rectTransform == null) |
| 12 | 55 | | rectTransform = GetComponent<RectTransform>(); |
| | 56 | |
|
| 12 | 57 | | rectTransform.localScale = new Vector3(scale, scale, 1f); |
| | 58 | |
|
| 12 | 59 | | highlighImage.rectTransform.sizeDelta = Vector2.zero; |
| 12 | 60 | | } |
| | 61 | |
|
| | 62 | | public void ChangeHighlighSize(Vector2Int newSize) |
| | 63 | | { |
| 0 | 64 | | highlighSize = new Vector2(18 * newSize.x, 18 * newSize.y); |
| 0 | 65 | | rectTransform.sizeDelta = highlighSize; |
| 0 | 66 | | } |
| | 67 | | } |