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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
public class TextBox : MonoBehaviour, IFocusHolder
{
public float TextHeight
{
get
{
return this.outputText.Height;
}
}
public static readonly HashSet<char> SymbolChars = new HashSet<char>
{
'?',
'!',
',',
'.',
'\'',
':',
';',
'(',
')',
'/',
'\\',
'%',
'^',
'&',
'-',
'='
};
public string text;
private string compoText = "";
public int characterLimit = -1;
[SerializeField]
private TextRenderer outputText;
public SpriteRenderer Background;
public MeshRenderer Pipe;
private float pipeBlinkTimer;
public bool ClearOnFocus;
public bool ForceUppercase;
public Button.ButtonClickedEvent OnEnter;
public Button.ButtonClickedEvent OnChange;
public Button.ButtonClickedEvent OnFocusLost;
private TouchScreenKeyboard keyboard;
public bool AllowSymbols;
public bool IpMode;
private Collider2D[] colliders;
private bool hasFocus;
private StringBuilder tempTxt = new StringBuilder();
public void Start()
{
this.colliders = base.GetComponents<Collider2D>();
DestroyableSingleton<PassiveButtonManager>.Instance.RegisterOne(this);
if (this.Pipe)
{
this.Pipe.enabled = false;
}
}
public void OnDestroy()
{
if (this.keyboard != null)
{
this.keyboard.active = false;
this.keyboard = null;
}
if (DestroyableSingleton<PassiveButtonManager>.InstanceExists)
{
DestroyableSingleton<PassiveButtonManager>.Instance.RemoveOne(this);
}
}
public void Clear()
{
this.SetText(string.Empty, string.Empty);
}
public void Update()
{
if (!this.hasFocus)
{
return;
}
string inputString = Input.inputString;
if (inputString.Length > 0 || this.compoText != Input.compositionString)
{
if (this.text == null || this.text == "Enter Name")
{
this.text = "";
}
this.SetText(this.text + inputString, Input.compositionString);
}
if (this.Pipe && this.hasFocus)
{
this.pipeBlinkTimer += Time.deltaTime * 2f;
this.Pipe.enabled = ((int)this.pipeBlinkTimer % 2 == 0);
}
}
public void GiveFocus()
{
Input.imeCompositionMode = IMECompositionMode.On;
if (this.hasFocus)
{
return;
}
if (this.ClearOnFocus)
{
this.text = string.Empty;
this.compoText = string.Empty;
this.outputText.Text = string.Empty;
}
this.hasFocus = true;
if (TouchScreenKeyboard.isSupported)
{
this.keyboard = TouchScreenKeyboard.Open(this.text);
}
if (this.Background)
{
this.Background.color = Color.green;
}
this.pipeBlinkTimer = 0f;
if (this.Pipe)
{
this.Pipe.transform.localPosition = this.outputText.CursorPos;
}
}
public void LoseFocus()
{
if (!this.hasFocus)
{
return;
}
Input.imeCompositionMode = IMECompositionMode.Off;
if (this.compoText.Length > 0)
{
this.SetText(this.text + this.compoText, "");
this.compoText = string.Empty;
}
this.hasFocus = false;
if (this.keyboard != null)
{
this.keyboard.active = false;
this.keyboard = null;
}
if (this.Background)
{
this.Background.color = Color.white;
}
if (this.Pipe)
{
this.Pipe.enabled = false;
}
this.OnFocusLost.Invoke();
}
public bool CheckCollision(Vector2 pt)
{
for (int i = 0; i < this.colliders.Length; i++)
{
if (this.colliders[i].OverlapPoint(pt))
{
return true;
}
}
return false;
}
public void SetText(string input, string inputCompo = "")
{
bool flag = false;
char c = ' ';
this.tempTxt.Clear();
foreach (char c2 in input)
{
if (c != ' ' || c2 != ' ')
{
if (c2 == '\r' || c2 == '\n')
{
flag = true;
}
if (c2 == '\b')
{
this.tempTxt.Length = Math.Max(this.tempTxt.Length - 1, 0);
}
if (this.ForceUppercase)
{
c2 = char.ToUpperInvariant(c2);
}
if (this.IsCharAllowed(c2))
{
this.tempTxt.Append(c2);
c = c2;
}
}
}
if (this.characterLimit > 0)
{
this.tempTxt.Length = Math.Min(this.tempTxt.Length, this.characterLimit);
}
input = this.tempTxt.ToString();
if (!input.Equals(this.text) || !inputCompo.Equals(this.compoText))
{
this.text = input;
this.compoText = inputCompo;
this.outputText.Text = this.text + "[FF0000FF]" + this.compoText + "[]";
this.outputText.RefreshMesh();
if (this.keyboard != null)
{
this.keyboard.text = this.text;
}
this.OnChange.Invoke();
}
if (flag)
{
this.OnEnter.Invoke();
}
if (this.Pipe)
{
this.Pipe.transform.localPosition = this.outputText.CursorPos;
}
}
public bool IsCharAllowed(char i)
{
if (this.IpMode)
{
return (i >= '0' && i <= '9') || i == '.';
}
return i == ' ' || (i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z') || (i >= '0' && i <= '9') || (i >= 'À' && i <= 'ÿ') || (i >= 'Ѐ' && i <= 'џ') || (i >= 'ㄱ' && i <= 'ㆎ') || (i >= '가' && i <= '힣') || (this.AllowSymbols && TextBox.SymbolChars.Contains(i));
}
}
|