Files
BeatSaber/Assets/Script/MarqueeText.cs
T
whdwo798 64ef3d64ec feat: SongSelect UI polish — marquee title, button states, font
- MarqueeText: scrolling title for long song names (RectMask2D clipped)
- SongDetailPanel: difficulty selected = green (img.color direct set)
- SongSelectManager: ALL/OWNED tab active state via img.color
- Card layout: DestroyImmediate + correct rebuild order to fix zero-size title bug
- NanumGothic SDF fallback configured on LiberationSans for Korean support

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 13:31:04 +09:00

56 lines
1.4 KiB
C#

using System.Collections;
using TMPro;
using UnityEngine;
[RequireComponent(typeof(TMP_Text))]
public class MarqueeText : MonoBehaviour
{
public float speed = 35f;
public float pauseStart = 1.5f;
public float pauseEnd = 0.6f;
private TMP_Text _label;
private RectTransform _rect;
private void Awake()
{
_label = GetComponent<TMP_Text>();
_rect = GetComponent<RectTransform>();
}
private IEnumerator Start()
{
yield return null; // layout 완료 후 실행
_label.ForceMeshUpdate();
float textW = _label.preferredWidth;
float containerW = ((RectTransform)transform.parent).rect.width;
float dist = textW - containerW;
if (dist > 1f)
StartCoroutine(ScrollLoop(dist));
}
private IEnumerator ScrollLoop(float dist)
{
while (true)
{
SetX(0f);
yield return new WaitForSeconds(pauseStart);
float x = 0f;
while (x > -dist)
{
x = Mathf.MoveTowards(x, -dist, speed * Time.deltaTime);
SetX(x);
yield return null;
}
yield return new WaitForSeconds(pauseEnd);
}
}
private void SetX(float x) =>
_rect.anchoredPosition = new Vector2(x, _rect.anchoredPosition.y);
}