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
|
import os
import json
import shutil
from math import trunc
def generate_ios_icons(xcode_project_path, icons_dir):
# 从 Xcode 11 工程 Images.xcassets/AppIcon.appiconset/Contents.json 转换生成
# 排列顺序调整为与 Unity 生成的一致,方便自动修改后比较文件内容
images_template = [
{
"size": 57,
"idiom": "iphone",
"scale": 1
},
{
"size": 57,
"idiom": "iphone",
"scale": 2
},
{
"size": 60,
"idiom": "iphone",
"scale": 2
},
{
"size": 60,
"idiom": "iphone",
"scale": 3
},
{
"size": 29,
"idiom": "iphone",
"scale": 1
},
{
"size": 29,
"idiom": "iphone",
"scale": 2
},
{
"size": 29,
"idiom": "iphone",
"scale": 3
},
{
"size": 40,
"idiom": "iphone",
"scale": 2
},
{
"size": 40,
"idiom": "iphone",
"scale": 3
},
{
"size": 20,
"idiom": "iphone",
"scale": 2
},
{
"size": 20,
"idiom": "iphone",
"scale": 3
},
{
"size": 29,
"idiom": "ipad",
"scale": 1
},
{
"size": 29,
"idiom": "ipad",
"scale": 2
},
{
"size": 40,
"idiom": "ipad",
"scale": 1
},
{
"size": 40,
"idiom": "ipad",
"scale": 2
},
{
"size": 50,
"idiom": "ipad",
"scale": 1
},
{
"size": 50,
"idiom": "ipad",
"scale": 2
},
{
"size": 72,
"idiom": "ipad",
"scale": 1
},
{
"size": 72,
"idiom": "ipad",
"scale": 2
},
{
"size": 76,
"idiom": "ipad",
"scale": 1
},
{
"size": 76,
"idiom": "ipad",
"scale": 2
},
{
"size": 20,
"idiom": "ipad",
"scale": 1
},
{
"size": 20,
"idiom": "ipad",
"scale": 2
},
{
"size": 83.5,
"idiom": "ipad",
"scale": 2
},
{
"size": 1024,
"idiom": "ios-marketing",
"scale": 1
}
]
appicon_dir = os.path.join(xcode_project_path, 'Unity-iPhone/Images.xcassets/AppIcon.appiconset')
cleared = False
images = []
for image_template in images_template:
icon_name = '{0}x{0}.png'.format(trunc(image_template['size'] * image_template['scale']))
icon_path = os.path.join(icons_dir, icon_name)
if not os.path.exists(icon_path):
continue
if not cleared:
for root, dirs, files in os.walk(appicon_dir):
for f in files:
os.unlink(os.path.join(root, f))
for d in dirs:
shutil.rmtree(os.path.join(root, d))
cleared = True
shutil.copy2(icon_path, appicon_dir)
image = {'filename': icon_name, 'idiom': image_template['idiom'],
'scale': '{0}x'.format(image_template['scale']), 'size': '{0}x{0}'.format(image_template['size'])}
images.append(image)
contents = {
'images': images,
'info': {
'author': 'xcode',
'version': 1
},
'properties': {
'pre-rendered': False
}
}
contents_path = os.path.join(xcode_project_path, 'Unity-iPhone/Images.xcassets/AppIcon.appiconset/Contents.json')
with open(contents_path, 'w', encoding='utf-8') as openfile:
json.dump(contents, openfile, indent=4, sort_keys=False, ensure_ascii=False)
# 36x36.png src/main/res/drawable-ldpi/app_icon.png
# 48x48.png src/main/res/drawable-mdpi/app_icon.png
# 72x72.png src/main/res/drawable/app_icon.png
# 72x72.png src/main/res/drawable-hdpi/app_icon.png
# 96x96.png src/main/res/drawable-xhdpi/app_icon.png
# 144x144.png src/main/res/drawable-xxhdpi/app_icon.png
# 192x192.png src/main/res/drawable-xxxhdpi/app_icon.png
def generate_android_icons(gradle_project_path, icons_dir):
icons_template = [
{
'size': 36,
'name': 'drawable-ldpi'
},
{
'size': 48,
'name': 'drawable-mdpi'
},
{
'size': 72,
'name': 'drawable'
},
{
'size': 72,
'name': 'drawable-hdpi'
},
{
'size': 96,
'name': 'drawable-xhdpi'
},
{
'size': 144,
'name': 'drawable-xxhdpi'
},
{
'size': 192,
'name': 'drawable-xxxhdpi'
},
]
for icon_template in icons_template:
icon_name = '{0}x{0}.png'.format(trunc(icon_template['size']))
icon_path = os.path.join(icons_dir, icon_name)
if not os.path.exists(icon_path):
continue
appicon_dir = os.path.join(gradle_project_path, 'src/main/res/{0}'.format(icon_template['name']))
if not os.path.exists(appicon_dir):
continue
appicon_path = os.path.join(appicon_dir, 'app_icon.png')
print(icon_path, appicon_path)
shutil.copy2(icon_path, appicon_path)
|