| | 1 | | using UnityEngine; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine.UI; |
| | 4 | | public class TacticalSymbol : MonoBehaviour { |
| | 5 | | [SerializeField] |
| | 6 | | private GameObject _directionArrow; |
| | 7 | | [SerializeField] |
| | 8 | | private TextMeshProUGUI _uniqueDesignatorText; |
| | 9 | | [SerializeField] |
| | 10 | | private TextMeshProUGUI _iffText; |
| | 11 | | [SerializeField] |
| | 12 | | private TextMeshProUGUI _typeText; |
| | 13 | | [SerializeField] |
| | 14 | | private TextMeshProUGUI _speedAltText; |
| | 15 | | [SerializeField] |
| | 16 | | private TextMeshProUGUI _additionalInfoText; |
| | 17 | |
|
| | 18 | | private SpriteManager _spriteManager; |
| | 19 | |
|
| 0 | 20 | | void Awake() { |
| 0 | 21 | | _spriteManager = new SpriteManager(); |
| 0 | 22 | | _uniqueDesignatorText.text = ""; |
| 0 | 23 | | _iffText.text = ""; |
| 0 | 24 | | _typeText.text = ""; |
| 0 | 25 | | _speedAltText.text = ""; |
| 0 | 26 | | _additionalInfoText.text = ""; |
| 0 | 27 | | } |
| | 28 | |
|
| 0 | 29 | | public void SetDirectionArrowRotation(float rotationDegrees) { |
| 0 | 30 | | if (_directionArrow != null) { |
| 0 | 31 | | _directionArrow.GetComponent<RectTransform>().rotation = |
| | 32 | | Quaternion.Euler(0, 0, rotationDegrees); |
| 0 | 33 | | } |
| 0 | 34 | | } |
| | 35 | |
|
| 0 | 36 | | public void DisableDirectionArrow() { |
| 0 | 37 | | if (_directionArrow != null) { |
| 0 | 38 | | _directionArrow.SetActive(false); |
| 0 | 39 | | } else { |
| 0 | 40 | | Debug.LogWarning("Direction arrow not found on TacticalSymbol" + name); |
| 0 | 41 | | } |
| 0 | 42 | | } |
| | 43 | |
|
| 0 | 44 | | public void SetSprite(string spriteName) { |
| 0 | 45 | | spriteName = spriteName.ToUpper(); |
| | 46 | | // Update main symbol image |
| 0 | 47 | | Image symbolImage = GetComponent<Image>(); |
| 0 | 48 | | if (symbolImage != null) { |
| 0 | 49 | | Sprite symbolSprite = _spriteManager.LoadSymbolSprite(spriteName); |
| 0 | 50 | | if (symbolSprite != null) { |
| 0 | 51 | | symbolImage.sprite = symbolSprite; |
| 0 | 52 | | } |
| 0 | 53 | | } |
| 0 | 54 | | } |
| | 55 | |
|
| 0 | 56 | | public void SetUniqueDesignator(string text) { |
| 0 | 57 | | SetText(_uniqueDesignatorText, text); |
| 0 | 58 | | } |
| | 59 | |
|
| 0 | 60 | | public void SetIFF(string text) { |
| 0 | 61 | | SetText(_iffText, text); |
| 0 | 62 | | } |
| | 63 | |
|
| 0 | 64 | | public void SetType(string text) { |
| 0 | 65 | | SetText(_typeText, text); |
| 0 | 66 | | } |
| | 67 | |
|
| 0 | 68 | | public void SetSpeedAlt(string text) { |
| 0 | 69 | | SetText(_speedAltText, text); |
| 0 | 70 | | } |
| | 71 | |
|
| 0 | 72 | | public void SetAdditionalInfo(string text) { |
| 0 | 73 | | SetText(_additionalInfoText, text); |
| 0 | 74 | | } |
| | 75 | |
|
| 0 | 76 | | private void SetText(TextMeshProUGUI textComponent, string text) { |
| 0 | 77 | | if (textComponent != null) { |
| 0 | 78 | | textComponent.text = text.ToUpper(); |
| 0 | 79 | | } |
| 0 | 80 | | } |
| | 81 | |
|
| 0 | 82 | | void Update() {} |
| | 83 | | } |
| | 84 | |
|
| | 85 | | public class SpriteManager { |
| | 86 | | private const string SymbolPathFormat = "APP6-D_Symbology/{0}"; |
| | 87 | |
|
| | 88 | | public Sprite LoadSymbolSprite(string symbolName) { |
| | 89 | | string path = string.Format(SymbolPathFormat, symbolName); |
| | 90 | | Sprite sprite = Resources.Load<Sprite>(path); |
| | 91 | | if (sprite == null) { |
| | 92 | | Debug.LogWarning($"Failed to load sprite at path: {path}"); |
| | 93 | | } |
| | 94 | | return sprite; |
| | 95 | | } |
| | 96 | | } |