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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
namespace I2.Loc;
public static class I2Utils
{
public const string ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
public const string NumberChars = "0123456789";
public const string ValidNameSymbols = ".-_$#@*()[]{}+:?!&',^=<>~`";
public static string ReverseText(string source)
{
int length = source.Length;
char[] output = new char[length];
char[] anyOf = new char[2] { '\r', '\n' };
int i = 0;
while (i < length)
{
int num = source.IndexOfAny(anyOf, i);
if (num < 0)
{
num = length;
}
Reverse(i, num - 1);
for (i = num; i < length && (source[i] == '\r' || source[i] == '\n'); i++)
{
output[i] = source[i];
}
}
return new string(output);
void Reverse(int start, int end)
{
for (int j = 0; j <= end - start; j++)
{
output[end - j] = source[start + j];
}
}
}
public static string RemoveNonASCII(string text, bool allowCategory = false)
{
if (string.IsNullOrEmpty(text))
{
return text;
}
int num = 0;
char[] array = new char[text.Length];
bool flag = false;
string text2 = text.Trim();
foreach (char c in text2)
{
char c2 = ' ';
if ((allowCategory && (c == '\\' || c == '"' || c == '/')) || char.IsLetterOrDigit(c) || ".-_$#@*()[]{}+:?!&',^=<>~`".IndexOf(c) >= 0)
{
c2 = c;
}
if (char.IsWhiteSpace(c2))
{
if (!flag)
{
if (num > 0)
{
array[num++] = ' ';
}
flag = true;
}
}
else
{
flag = false;
array[num++] = c2;
}
}
return new string(array, 0, num);
}
public static string GetValidTermName(string text, bool allowCategory = false)
{
if (text == null)
{
return null;
}
text = RemoveTags(text);
return RemoveNonASCII(text, allowCategory);
}
public static string SplitLine(string line, int maxCharacters)
{
if (maxCharacters <= 0 || line.Length < maxCharacters)
{
return line;
}
char[] array = line.ToCharArray();
bool flag = true;
bool flag2 = false;
int i = 0;
int num = 0;
for (; i < array.Length; i++)
{
if (flag)
{
num++;
if (array[i] == '\n')
{
num = 0;
}
if (num >= maxCharacters && char.IsWhiteSpace(array[i]))
{
array[i] = '\n';
flag = false;
flag2 = false;
}
}
else if (!char.IsWhiteSpace(array[i]))
{
flag = true;
num = 0;
}
else if (array[i] != '\n')
{
array[i] = '\0';
}
else
{
if (!flag2)
{
array[i] = '\0';
}
flag2 = true;
}
}
return new string(array.Where((char c) => c != '\0').ToArray());
}
public static bool FindNextTag(string line, int iStart, out int tagStart, out int tagEnd)
{
tagStart = -1;
tagEnd = -1;
int length = line.Length;
tagStart = iStart;
while (tagStart < length && line[tagStart] != '[' && line[tagStart] != '(' && line[tagStart] != '{' && line[tagStart] != '<')
{
tagStart++;
}
if (tagStart == length)
{
return false;
}
bool flag = false;
for (tagEnd = tagStart + 1; tagEnd < length; tagEnd++)
{
char c = line[tagEnd];
if (c == ']' || c == ')' || c == '}' || c == '>')
{
if (flag)
{
return FindNextTag(line, tagEnd + 1, out tagStart, out tagEnd);
}
return true;
}
if (c > 'ΓΏ')
{
flag = true;
}
}
return false;
}
public static string RemoveTags(string text)
{
return Regex.Replace(text, "\\{\\[(.*?)]}|\\[(.*?)]|\\<(.*?)>", "");
}
public static bool RemoveResourcesPath(ref string sPath)
{
int num = sPath.IndexOf("\\Resources\\", StringComparison.Ordinal);
int num2 = sPath.IndexOf("\\Resources/", StringComparison.Ordinal);
int num3 = sPath.IndexOf("/Resources\\", StringComparison.Ordinal);
int num4 = sPath.IndexOf("/Resources/", StringComparison.Ordinal);
int num5 = Mathf.Max(num, num2, num3, num4);
bool result = false;
if (num5 >= 0)
{
sPath = sPath.Substring(num5 + 11);
result = true;
}
else
{
num5 = sPath.LastIndexOfAny(LanguageSourceData.CategorySeparators);
if (num5 > 0)
{
sPath = sPath.Substring(num5 + 1);
}
}
string extension = Path.GetExtension(sPath);
if (!string.IsNullOrEmpty(extension))
{
sPath = sPath.Substring(0, sPath.Length - extension.Length);
}
return result;
}
public static bool IsPlaying()
{
if (Application.isPlaying)
{
return true;
}
return false;
}
public static string GetPath(this Transform tr)
{
Transform parent = tr.parent;
if (tr == null)
{
return tr.name;
}
return parent.GetPath() + "/" + tr.name;
}
public static Transform FindObject(string objectPath)
{
return FindObject(SceneManager.GetActiveScene(), objectPath);
}
public static Transform FindObject(Scene scene, string objectPath)
{
GameObject[] rootGameObjects = scene.GetRootGameObjects();
for (int i = 0; i < rootGameObjects.Length; i++)
{
Transform transform = rootGameObjects[i].transform;
if (transform.name == objectPath)
{
return transform;
}
if (objectPath.StartsWith(transform.name + "/", StringComparison.Ordinal))
{
return FindObject(transform, objectPath.Substring(transform.name.Length + 1));
}
}
return null;
}
public static Transform FindObject(Transform root, string objectPath)
{
for (int i = 0; i < root.childCount; i++)
{
Transform child = root.GetChild(i);
if (child.name == objectPath)
{
return child;
}
if (objectPath.StartsWith(child.name + "/", StringComparison.Ordinal))
{
return FindObject(child, objectPath.Substring(child.name.Length + 1));
}
}
return null;
}
public static H FindInParents<H>(Transform tr) where H : Component
{
if (!tr)
{
return null;
}
H component = tr.GetComponent<H>();
while (!(UnityEngine.Object)component && (bool)tr)
{
component = tr.GetComponent<H>();
tr = tr.parent;
}
return component;
}
public static string GetCaptureMatch(Match match)
{
for (int num = match.Groups.Count - 1; num >= 0; num--)
{
if (match.Groups[num].Success)
{
return match.Groups[num].ToString();
}
}
return match.ToString();
}
public static void SendWebRequest(UnityWebRequest www)
{
www.SendWebRequest();
}
}
|