Filesystem.mm
5.08 KB
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
#include <sys/xattr.h>
#include "UnityInterface.h"
#include <cstring>
static NSString* bundleIdWithData = nil;
extern "C" void UnitySetDataBundleDirWithBundleId(const char* bundleId)
{
if (bundleId) bundleIdWithData = [NSString stringWithUTF8String: bundleId];
else bundleIdWithData = nil;
}
extern "C" const char* UnityDataBundleDir()
{
static const char* dir = NULL;
if (dir == NULL)
{
if (bundleIdWithData == nil)
dir = AllocCString([[NSBundle mainBundle] bundlePath]);
else
dir = AllocCString([[NSBundle bundleWithIdentifier: bundleIdWithData] bundlePath]);
}
return dir;
}
#define RETURN_SPECIAL_DIR(dir) \
do { \
static const char* var = NULL; \
if (var == NULL) \
var = AllocCString(NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES)[0]); \
return var; \
} while (0)
extern "C" const char* UnityDocumentsDir()
{
RETURN_SPECIAL_DIR(NSDocumentDirectory);
}
extern "C" const char* UnityLibraryDir()
{
RETURN_SPECIAL_DIR(NSLibraryDirectory);
}
extern "C" const char* UnityCachesDir()
{
RETURN_SPECIAL_DIR(NSCachesDirectory);
}
#undef RETURN_SPECIAL_DIR
extern "C" int UnityUpdateNoBackupFlag(const char* path, int setFlag)
{
int result;
if (setFlag)
{
u_int8_t b = 1;
result = ::setxattr(path, "com.apple.MobileBackup", &b, 1, 0, 0);
}
else
{
result = ::removexattr(path, "com.apple.MobileBackup", 0);
}
return result == 0 ? 1 : 0;
}
extern "C" const char* const* UnityFontFallbacks()
{
/* The following is the family names of fonts that are used as fallbacks
for characters that were not fount in user-specified fonts. Add more
fonts and/or reorder the list to fit your needs. For certain character
NOTE: Some similar Chinese, Japanese and Korean characters share the
character number in Unicode, but are written differently. To display
such characters properly, correct font must be selected. We reorder
the fonts list on the first run of this function.
*/
static const char** cachedFonts = NULL;
if (cachedFonts == NULL)
{
const int fontsToReorderCount = 4;
static const char* defaultFonts[] =
{
// first fontsToReorderCount items will be reordered if needed.
"Hiragino Kaku Gothic ProN", // Japanese characters
"Heiti TC", // Traditional Chinese characters (on 9.0 OS substitutes this with "PingFang TC")
"Heiti SC", // Simplified Chinese characters (on 9.0 OS substitutes this with "PingFang SC")
"Apple SD Gothic Neo", // Korean characters
".Sukhumvit Set UI", // Thai characters since 8.2 until 9.x
"AppleGothic",
"Noto Sans Yi", // Yi characters on 9.0 (not available on tvOS)
"Helvetica",
"Helvetica Neue",
"Arial Hebrew", // Hebrew since 9.0
"Kohinoor Devanagari", // Hindi since 9.0
"Kohinoor Bangla", // Bengali since 9.0
"Kohinoor Telugu", // Telugu since 9.0
"Lao Sangam MN", // Lao
"Geeza Pro", // Arabic
"Kailasa", // Tibetan since iOS 10.0
".PhoneFallback", // Armenian, Braille, Georgian, Thai, various symbols since iOS 10.0
// Note that iOS itself prefers Thonburi font for the Thai characters, but our font subsystem
// can't display combining characters for some reason
".LastResort",
NULL
};
// The default works for Japanese, we won't reorder in that case
static const char* koFontOrder[] =
{
"Apple SD Gothic Neo", // Korean characters
"Hiragino Kaku Gothic ProN", // Japanese characters
"Heiti TC", // Traditional Chinese characters (on 9.0 OS substitutes this with "PingFang TC")
"Heiti SC", // Simplified Chinese characters (on 9.0 OS substitutes this with "PingFang SC")
};
static const char* zhFontOrder[] =
{
"Heiti TC", // Traditional Chinese characters (on 9.0 OS substitutes this with "PingFang TC")
"Heiti SC", // Simplified Chinese characters (on 9.0 OS substitutes this with "PingFang SC")
"Hiragino Kaku Gothic ProN", // Japanese characters
"Apple SD Gothic Neo", // Korean characters
};
const char* lang = UnitySystemLanguage();
const char** fontOrderOverride = NULL;
if (std::strncmp(lang, "ko", 2) == 0)
fontOrderOverride = koFontOrder;
if (std::strncmp(lang, "zh", 2) == 0)
fontOrderOverride = zhFontOrder;
if (fontOrderOverride)
{
for (int i = 0; i < fontsToReorderCount; ++i)
defaultFonts[i] = fontOrderOverride[i];
}
cachedFonts = defaultFonts;
}
return cachedFonts;
}