Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class UITextEllipsisOverflow : UIBehaviour
[SerializeField] [Tooltip("If set to true, the text will actually be overwritten in EditMode.")]
private bool _applyInEditMode = true;

private string _textValue;
private string _textValue = string.Empty;
private string _originalTextValue = string.Empty;

protected override void Awake()
{
Expand All @@ -24,6 +25,7 @@ protected override void Awake()
{
_text = GetComponent<Text>();
_textValue = _text.text;
_originalTextValue = _text.text;
}
}

Expand All @@ -32,8 +34,9 @@ private void Update()
if (_text.text == _textValue)
return;

_textValue = _text.text;
_originalTextValue = _text.text;
Apply();
_textValue = _text.text;
}

protected override void OnRectTransformDimensionsChange()
Expand All @@ -57,12 +60,12 @@ private void Apply()

if (!IsActive() || _text == null) return;

var text = _originalTextValue;

var rectTransform = _text.rectTransform;
var generator = _text.cachedTextGenerator;
var settings = _text.GetGenerationSettings(rectTransform.rect.size);
generator.Populate(_text.text, settings);

var text = _text.text;
generator.Populate(text, settings);

if (rectTransform.rect.width <= 0 || rectTransform.rect.height <= 0)
// Do nothing because the layout seems not to have been built yet.
Expand Down