| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | [ExecuteInEditMode] |
| | 5 | | public class PrivateChatEntryBackgroundFitter : MonoBehaviour |
| | 6 | | { |
| | 7 | | public RectTransform rectTransform; |
| | 8 | | public RectTransform parentContainerRectTransform; |
| | 9 | | public TextMeshProUGUI messageText; |
| 0 | 10 | | public bool leftMessage = true; |
| | 11 | |
|
| | 12 | | void Update() |
| | 13 | | { |
| 0 | 14 | | Vector2 textSize = new Vector2(messageText.bounds.size.x + messageText.margin.x + messageText.margin.z, |
| | 15 | | messageText.bounds.size.y + messageText.margin.y * 2); |
| | 16 | |
|
| 0 | 17 | | messageText.transform.localPosition = new Vector3(leftMessage ? (messageText.margin.x + messageText.margin.z) / |
| | 18 | |
|
| 0 | 19 | | if (parentContainerRectTransform) |
| | 20 | | { |
| 0 | 21 | | parentContainerRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, textSize.x); |
| 0 | 22 | | parentContainerRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, textSize.y); |
| 0 | 23 | | parentContainerRectTransform.ForceUpdateRectTransforms(); |
| | 24 | | } |
| | 25 | |
|
| 0 | 26 | | rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, textSize.x); |
| 0 | 27 | | rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, textSize.y); |
| 0 | 28 | | rectTransform.ForceUpdateRectTransforms(); |
| 0 | 29 | | } |
| | 30 | | } |