feat : Add spacing between letters
This commit is contained in:
@@ -334,9 +334,9 @@ MonoBehaviour:
|
|||||||
- {fileID: 11400000, guid: d2b009825e5fdef4197bfa70e59bf349, type: 2}
|
- {fileID: 11400000, guid: d2b009825e5fdef4197bfa70e59bf349, type: 2}
|
||||||
- {fileID: 11400000, guid: d612f7901720205498d63ae1fd6b556d, type: 2}
|
- {fileID: 11400000, guid: d612f7901720205498d63ae1fd6b556d, type: 2}
|
||||||
- {fileID: 11400000, guid: d5dd43cfa59c82841a5110cf1c54cfd6, type: 2}
|
- {fileID: 11400000, guid: d5dd43cfa59c82841a5110cf1c54cfd6, type: 2}
|
||||||
_shiftInterval: 3
|
_shiftInterval: 0.5
|
||||||
_minLetterDelay: 0.05
|
_minLetterDelay: 0.05
|
||||||
_maxLetterDelay: 0.25
|
_maxLetterDelay: 0.45
|
||||||
_fontSize: 86
|
_fontSize: 86
|
||||||
_textColor: {r: 1, g: 1, b: 1, a: 1}
|
_textColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
--- !u!114 &744399719
|
--- !u!114 &744399719
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Unheimlich.UI
|
namespace Unheimlich.UI
|
||||||
{
|
{
|
||||||
@@ -108,25 +109,25 @@ namespace Unheimlich.UI
|
|||||||
|
|
||||||
private void ArrangeLetters()
|
private void ArrangeLetters()
|
||||||
{
|
{
|
||||||
float totalWidth = 0f;
|
HorizontalLayoutGroup layout = gameObject.GetComponent<HorizontalLayoutGroup>();
|
||||||
List<float> letterWidths = new List<float>();
|
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)
|
foreach (TextMeshProUGUI letter in _letterObjects)
|
||||||
{
|
{
|
||||||
letter.ForceMeshUpdate();
|
ContentSizeFitter fitter = letter.gameObject.GetComponent<ContentSizeFitter>();
|
||||||
float width = letter.preferredWidth;
|
if (fitter == null)
|
||||||
letterWidths.Add(width);
|
fitter = letter.gameObject.AddComponent<ContentSizeFitter>();
|
||||||
totalWidth += width;
|
|
||||||
}
|
|
||||||
|
|
||||||
float currentX = -totalWidth / 2f;
|
fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||||
|
fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user