| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL.Controllers.HUD.SettingsPanelHUD |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// Adjust x position to be at the end of the text (with offset) |
| | 8 | | /// </summary> |
| | 9 | | public class PositionAdjusterByEndOfText : MonoBehaviour |
| | 10 | | { |
| | 11 | | [SerializeField] private TMP_Text titleText; |
| 57 | 12 | | [SerializeField] private float offset = 25f; |
| | 13 | |
|
| | 14 | | private RectTransform rectTransform; |
| | 15 | |
|
| | 16 | | private float containerWidth; |
| | 17 | |
|
| | 18 | | private void Awake() |
| | 19 | | { |
| 43 | 20 | | rectTransform = GetComponent<RectTransform>(); |
| 43 | 21 | | containerWidth = titleText.rectTransform.rect.width; |
| 43 | 22 | | } |
| | 23 | |
|
| | 24 | | private void OnEnable() |
| | 25 | | { |
| 43 | 26 | | SetPositionWithOffsetFromTextEnd(); |
| 43 | 27 | | } |
| | 28 | |
|
| | 29 | | private void SetPositionWithOffsetFromTextEnd() |
| | 30 | | { |
| 43 | 31 | | Vector3 newPos = rectTransform.localPosition; |
| 43 | 32 | | newPos.x = titleText.preferredWidth - (containerWidth / 2) + offset; |
| | 33 | |
|
| 43 | 34 | | rectTransform.localPosition = newPos; |
| 43 | 35 | | } |
| | 36 | | } |
| | 37 | | } |