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