-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTextRefresher.cs
75 lines (64 loc) · 1.46 KB
/
TextRefresher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using Assets.Scripts.Core;
using TMPro;
using UnityEngine;
public class TextRefresher : MonoBehaviour
{
private bool isFullscreen;
private int width;
private bool language;
private UILabel label;
private TextMeshPro textMesh;
public string English;
public string Japanese;
private void UpdateText()
{
if (textMesh != null)
{
textMesh.text = ((!language) ? Japanese : English);
// Game places the main menu at y +2, which puts them a bit too high in their boxes.
if (System.Math.Abs(textMesh.transform.localPosition.y - 2f) < 0.1)
{
Vector3 localPosition = textMesh.transform.localPosition;
localPosition.y = 1f;
textMesh.transform.localPosition = localPosition;
}
}
else
{
label.text = ((!language) ? Japanese : English);
label.UpdateNGUIText();
}
}
private void Start()
{
isFullscreen = Screen.fullScreen;
width = Screen.width;
language = GameSystem.Instance.UseEnglishText;
label = GetComponent<UILabel>();
textMesh = GetComponent<TextMeshPro>();
UpdateText();
}
private void Update()
{
if (Screen.fullScreen != isFullscreen)
{
isFullscreen = Screen.fullScreen;
UpdateText();
}
if (width != Screen.width)
{
width = Screen.width;
UpdateText();
}
if (language != GameSystem.Instance.UseEnglishText)
{
language = GameSystem.Instance.UseEnglishText;
UpdateText();
}
}
public void SetFontSize(float size)
{
if (textMesh == null) { return; }
textMesh.fontSize = size;
}
}