2026-11-03 19:10:10 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace TKS
|
|
|
|
|
{
|
|
|
|
|
/// <summary>한글 표시용 폰트와 월드 텍스트(TextMesh) 생성.</summary>
|
|
|
|
|
public static class TextUtil
|
|
|
|
|
{
|
|
|
|
|
static Font font;
|
|
|
|
|
|
2026-11-11 05:38:15 +00:00
|
|
|
/// <summary>본문 폰트 = UI 테마 body(넥슨 Lv1 고딕 · ui_theme.csv) · 테마 없으면 OS 한글 폰트.</summary>
|
2026-11-03 19:10:10 +00:00
|
|
|
public static Font Font
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2026-11-11 05:38:15 +00:00
|
|
|
var th = UITheme.Current;
|
|
|
|
|
if (th != null && th.bodyFont != null) return th.bodyFont;
|
2026-11-03 19:10:10 +00:00
|
|
|
if (font == null) font = LoadFont();
|
|
|
|
|
return font;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-11 05:38:15 +00:00
|
|
|
/// <summary>굵은 본문 폰트(테마 body_bold) · 없으면 null.</summary>
|
|
|
|
|
public static Font BoldFont
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var th = UITheme.Current;
|
|
|
|
|
return th != null ? th.bodyBoldFont : null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>본문 글자 폰트·굵기 — 굵은 폰트 파일이 있으면 그것을 보통 굵기로(굵게 흉내를 겹치지 않음).</summary>
|
|
|
|
|
public static void UseBody(UnityEngine.UI.Text t, bool bold)
|
|
|
|
|
{
|
|
|
|
|
var b = bold ? BoldFont : null;
|
|
|
|
|
t.font = b != null ? b : Font;
|
|
|
|
|
t.fontStyle = bold && b == null ? FontStyle.Bold : FontStyle.Normal;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-03 19:10:10 +00:00
|
|
|
static Font LoadFont()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var f = UnityEngine.Font.CreateDynamicFontFromOSFont(
|
|
|
|
|
new[] { "Malgun Gothic", "맑은 고딕", "NanumGothic", "Noto Sans CJK KR", "Apple SD Gothic Neo", "Arial" }, 32);
|
|
|
|
|
if (f != null) return f;
|
|
|
|
|
}
|
|
|
|
|
catch (System.Exception e)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("[TKS] OS 폰트 로드 실패 → 내장 폰트 사용: " + e.Message);
|
|
|
|
|
}
|
|
|
|
|
return Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-23 12:42:17 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// 월드 좌표에 놓는 텍스트(전투 이름표 · 피해 숫자 · 스킬 이름 등). worldHeight = 글자 높이(월드 단위).
|
|
|
|
|
/// 글꼴 = 테마 제목 글꼴(메이플스토리체 · 2026-11-21 PD 전투 UI 재설계 「인게임 폰트가 게임 화풍과 안 맞음」 = 전투 화면 본문 글꼴 0) · 테마 없으면 본문.
|
|
|
|
|
/// </summary>
|
2026-11-03 19:10:10 +00:00
|
|
|
public static TextMesh CreateWorldText(Transform parent, string text, float worldHeight, Color color, int sortingOrder,
|
|
|
|
|
TextAnchor anchor = TextAnchor.MiddleCenter)
|
|
|
|
|
{
|
|
|
|
|
var go = new GameObject("Text");
|
|
|
|
|
go.transform.SetParent(parent, false);
|
|
|
|
|
var tm = go.AddComponent<TextMesh>();
|
2026-11-23 12:42:17 +00:00
|
|
|
var f = UISkin.TitleFont;
|
|
|
|
|
tm.font = f;
|
2026-11-03 19:10:10 +00:00
|
|
|
tm.fontSize = 64;
|
|
|
|
|
tm.characterSize = worldHeight * 10f / 64f;
|
|
|
|
|
tm.text = text;
|
|
|
|
|
tm.color = color;
|
|
|
|
|
tm.anchor = anchor;
|
|
|
|
|
tm.alignment = TextAlignment.Center;
|
|
|
|
|
tm.richText = false;
|
|
|
|
|
var mr = go.GetComponent<MeshRenderer>();
|
2026-11-23 12:42:17 +00:00
|
|
|
mr.sharedMaterial = f.material;
|
2026-11-03 19:10:10 +00:00
|
|
|
mr.sortingOrder = sortingOrder;
|
|
|
|
|
return tm;
|
|
|
|
|
}
|
2026-11-23 12:42:17 +00:00
|
|
|
|
|
|
|
|
/// <summary>월드 글자 한 줄의 폭(월드 · 글꼴 글자 폭 합 · 만든 직후에도 맞음 — 렌더러 bounds 는 그 프레임에 아직 0 일 수 있음).</summary>
|
|
|
|
|
public static float WorldTextWidth(TextMesh tm)
|
|
|
|
|
{
|
|
|
|
|
if (tm == null || tm.font == null || string.IsNullOrEmpty(tm.text)) return 0f;
|
|
|
|
|
tm.font.RequestCharactersInTexture(tm.text, tm.fontSize, tm.fontStyle);
|
|
|
|
|
float w = 0f;
|
|
|
|
|
CharacterInfo ci;
|
|
|
|
|
foreach (char c in tm.text)
|
|
|
|
|
if (tm.font.GetCharacterInfo(c, out ci, tm.fontSize, tm.fontStyle)) w += ci.advance;
|
|
|
|
|
return w * tm.characterSize * 0.1f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 월드 글자 외곽선 = 같은 글자 어두운 사본 4개를 상하좌우로 d(월드) 밀어 뒤에 깖(TextMesh 는 외곽선 효과가 없음 · 같은 글꼴 재질이라 한 번에 그려짐) ·
|
|
|
|
|
/// 글자가 바뀌면 사본도 따라 바뀜(<see cref="WorldTextOutline"/>).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void WorldOutline(TextMesh tm, Color c, float d)
|
|
|
|
|
{
|
|
|
|
|
if (tm == null || d <= 0f || tm.GetComponent<WorldTextOutline>() != null) return;
|
|
|
|
|
tm.gameObject.AddComponent<WorldTextOutline>().Init(tm, c, d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>월드 글자 바꾸기 — 외곽선 사본이 있으면 같이(<see cref="WorldOutline"/>).</summary>
|
|
|
|
|
public static void SetWorldText(TextMesh tm, string s)
|
|
|
|
|
{
|
|
|
|
|
if (tm == null) return;
|
|
|
|
|
var o = tm.GetComponent<WorldTextOutline>();
|
|
|
|
|
if (o != null) o.Set(s);
|
|
|
|
|
else if (tm.text != s) tm.text = s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>월드 글자(TextMesh) 외곽선 사본 4개 — 원본 글자가 바뀔 때만 사본 글자를 맞춤(매 프레임 = 문자열 참조 비교 1번).</summary>
|
|
|
|
|
public class WorldTextOutline : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
TextMesh src;
|
|
|
|
|
readonly TextMesh[] copies = new TextMesh[4];
|
|
|
|
|
string last;
|
|
|
|
|
|
|
|
|
|
public void Init(TextMesh tm, Color c, float d)
|
|
|
|
|
{
|
|
|
|
|
src = tm;
|
|
|
|
|
var mr = tm.GetComponent<MeshRenderer>();
|
|
|
|
|
var offs = new[] { new Vector2(d, 0f), new Vector2(-d, 0f), new Vector2(0f, d), new Vector2(0f, -d) };
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
var go = new GameObject("Outline");
|
|
|
|
|
go.transform.SetParent(tm.transform, false);
|
|
|
|
|
go.transform.localPosition = new Vector3(offs[i].x / Mathf.Max(0.0001f, tm.transform.lossyScale.x), offs[i].y / Mathf.Max(0.0001f, tm.transform.lossyScale.y), 0f);
|
|
|
|
|
var s = go.AddComponent<TextMesh>();
|
|
|
|
|
s.font = tm.font;
|
|
|
|
|
s.fontSize = tm.fontSize;
|
|
|
|
|
s.characterSize = tm.characterSize;
|
|
|
|
|
s.text = tm.text;
|
|
|
|
|
s.color = c;
|
|
|
|
|
s.anchor = tm.anchor;
|
|
|
|
|
s.alignment = tm.alignment;
|
|
|
|
|
s.richText = false;
|
|
|
|
|
var smr = go.GetComponent<MeshRenderer>();
|
|
|
|
|
smr.sharedMaterial = mr.sharedMaterial;
|
|
|
|
|
smr.sortingLayerID = mr.sortingLayerID;
|
|
|
|
|
smr.sortingOrder = mr.sortingOrder - 1;
|
|
|
|
|
copies[i] = s;
|
|
|
|
|
}
|
|
|
|
|
last = tm.text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>원본 · 사본 글자를 함께 바꿈(같으면 아무것도 안 함 · TextMesh.text 읽기는 매번 새 문자열이라 매 프레임 비교하지 않음).</summary>
|
|
|
|
|
public void Set(string s)
|
|
|
|
|
{
|
|
|
|
|
if (src == null || s == last) return;
|
|
|
|
|
last = s;
|
|
|
|
|
src.text = s;
|
|
|
|
|
foreach (var c in copies)
|
|
|
|
|
if (c != null) c.text = s;
|
|
|
|
|
}
|
2026-11-03 19:10:10 +00:00
|
|
|
}
|
|
|
|
|
}
|