Files
jongjae0305 c335995a9a feat: update song selection, score UI, and song creator features
- SongSelectManager/SongDetailPanel: 곡 선택 및 상세 패널 개선
- SongCreatorManager: 곡 생성 기능 추가
- FinalScoreLabel/ScoreManager: 결과 화면 점수 UI 업데이트
- MarqueeText: 마퀴 텍스트 컴포넌트 개선
- NoteData/SongController: 노트 데이터 및 컨트롤러 보완

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 17:29:50 +09:00

81 lines
1.8 KiB
C#

using System.Collections;
using TMPro;
using UnityEngine;
[RequireComponent(typeof(TMP_Text))]
public class MarqueeText : MonoBehaviour
{
public float speed = 14f;
public float pauseStart = 1.8f;
public float pauseEnd = 0.9f;
private TMP_Text _label;
private RectTransform _rect;
private Coroutine _scrollRoutine;
private void Awake()
{
_label = GetComponent<TMP_Text>();
_rect = GetComponent<RectTransform>();
}
private IEnumerator Start()
{
yield return null;
Refresh();
}
private void OnDisable()
{
StopScrolling();
}
public void Refresh()
{
if (!isActiveAndEnabled || _label == null || _rect == null || transform.parent == null)
return;
StopScrolling();
SetX(0f);
_label.ForceMeshUpdate();
float textW = _label.preferredWidth;
float containerW = ((RectTransform)transform.parent).rect.width;
float dist = textW - containerW;
if (dist > 1f)
_scrollRoutine = 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);
private void StopScrolling()
{
if (_scrollRoutine == null)
return;
StopCoroutine(_scrollRoutine);
_scrollRoutine = null;
}
}