글로벌 오브젝트 추가
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -36,10 +37,38 @@ public sealed class Typewriter
|
||||
// 지금 적용할 스타일 (글자 색 오버라이드 판단용). 연출 없이 표시했으면 null
|
||||
public TypewriterStyle Style => _style;
|
||||
|
||||
// Label.text에 그대로 넣을 문자열. 아직 안 드러난 뒷부분은 투명 처리돼 있다
|
||||
public string Composed => _cursor >= _full.Length
|
||||
? _full
|
||||
: _full.Substring(0, _cursor) + HIDE_TAG + _full.Substring(_cursor);
|
||||
// Label.text에 그대로 넣을 문자열. 아직 안 드러난 뒷부분은 투명 처리돼 있다.
|
||||
//
|
||||
// 뒷부분의 태그마다 <alpha=#00>을 다시 선언하는 게 핵심이다:
|
||||
// <color=...>나 </color>는 색을 (재)지정하면서 알파까지 같이 덮으므로, 앞에 한 번만 걸어둔
|
||||
// <alpha=#00>이 풀려 아직 안 나온 글자가 보여 버린다. 뒷부분은 전부 숨겨야 하는 구간이니
|
||||
// 태그가 끝날 때마다 투명도를 다시 못박는 게 항상 옳다.
|
||||
public string Composed
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cursor >= _full.Length) return _full;
|
||||
|
||||
var sb = new StringBuilder(_full.Length + 32);
|
||||
sb.Append(_full, 0, _cursor);
|
||||
sb.Append(HIDE_TAG);
|
||||
|
||||
for (int i = _cursor; i < _full.Length; i++)
|
||||
{
|
||||
char c = _full[i];
|
||||
sb.Append(c);
|
||||
if (c != '<') continue;
|
||||
|
||||
int close = _full.IndexOf('>', i + 1);
|
||||
if (close < 0) continue; // 닫히지 않은 '<' — 평범한 글자로 취급
|
||||
|
||||
sb.Append(_full, i + 1, close - i); // 태그 나머지 + '>'
|
||||
sb.Append(HIDE_TAG); // 색이 되돌아갔을 수 있으니 다시 숨긴다
|
||||
i = close;
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// 새 텍스트로 타이핑을 시작한다. style이 null이면 연출 없이 즉시 전체 표시.
|
||||
// token은 소유자(MonoBehaviour)의 destroyCancellationToken을 넘길 것.
|
||||
|
||||
Reference in New Issue
Block a user