feat : Add spacing between letters

This commit is contained in:
Jahnisse
2026-05-29 12:16:25 +02:00
parent 68a6940471
commit d486853a9d
2 changed files with 18 additions and 17 deletions
@@ -334,9 +334,9 @@ MonoBehaviour:
- {fileID: 11400000, guid: d2b009825e5fdef4197bfa70e59bf349, type: 2}
- {fileID: 11400000, guid: d612f7901720205498d63ae1fd6b556d, type: 2}
- {fileID: 11400000, guid: d5dd43cfa59c82841a5110cf1c54cfd6, type: 2}
_shiftInterval: 3
_shiftInterval: 0.5
_minLetterDelay: 0.05
_maxLetterDelay: 0.25
_maxLetterDelay: 0.45
_fontSize: 86
_textColor: {r: 1, g: 1, b: 1, a: 1}
--- !u!114 &744399719
@@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
namespace Unheimlich.UI
{
@@ -108,25 +109,25 @@ namespace Unheimlich.UI
private void ArrangeLetters()
{
float totalWidth = 0f;
List<float> letterWidths = new List<float>();
HorizontalLayoutGroup layout = gameObject.GetComponent<HorizontalLayoutGroup>();
if (layout == null)
layout = gameObject.AddComponent<HorizontalLayoutGroup>();
layout.childAlignment = TextAnchor.MiddleCenter;
layout.childForceExpandWidth = false;
layout.childForceExpandHeight = false;
layout.childControlWidth = true;
layout.childControlHeight = true;
layout.spacing = 0f;
foreach (TextMeshProUGUI letter in _letterObjects)
{
letter.ForceMeshUpdate();
float width = letter.preferredWidth;
letterWidths.Add(width);
totalWidth += width;
}
ContentSizeFitter fitter = letter.gameObject.GetComponent<ContentSizeFitter>();
if (fitter == null)
fitter = letter.gameObject.AddComponent<ContentSizeFitter>();
float currentX = -totalWidth / 2f;
for (int i = 0; i < _letterObjects.Count; i++)
{
RectTransform rt = _letterObjects[i].GetComponent<RectTransform>();
rt.anchoredPosition = new Vector2(currentX + letterWidths[i] / 2f, 0f);
rt.sizeDelta = new Vector2(letterWidths[i] + 2f, _fontSize * 1.5f);
currentX += letterWidths[i];
fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
}
}