-
Notifications
You must be signed in to change notification settings - Fork 10
/
ProjectBuild.cs
535 lines (479 loc) · 16.9 KB
/
ProjectBuild.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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using System.IO;
using System;
public class ProjectBuild
{
/// <summary>
/// 所有要打包的场景
/// </summary>
/// <value>The get build scenes.</value>
static string[] GetBuildScenes
{
get
{
List<string> list = new List<string>();
foreach (EditorBuildSettingsScene es in EditorBuildSettings.scenes)
{
if (es != null && es.enabled)
{
string fileName = Path.GetFileNameWithoutExtension(es.path);
if (!fileName.Contains("Transfer"))
{
list.Add(es.path);
}
}
}
return list.ToArray();
}
}
static string[] GetTransBuildScenes
{
get
{
List<string> list = new List<string>();
foreach (EditorBuildSettingsScene es in EditorBuildSettings.scenes)
{
if (es != null && es.enabled)
{
string fileName = Path.GetFileNameWithoutExtension(es.path);
if (fileName.Contains("Transfer"))
{
list.Add(es.path);
}
//list.Add(es.path);
}
}
return list.ToArray();
}
}
static Dictionary<string,bool> buildGames
{
get
{
Dictionary<string, bool> dic = new Dictionary<string, bool>();
string[] strs = System.Environment.GetCommandLineArgs();
foreach (string str in strs)
{
if (str.StartsWith("buildgmaes"))
{
string buildgmaes = str.Replace("buildgmaes=", "");
string[] builds = buildgmaes.Split('|');//.Replace("version=", "");
foreach (string build in builds)
{
string[] bs = build.Split('=');
dic[bs[0]] = bool.Parse(bs[1]);
}
}
}
return dic;
}
}
static BuildTargetGroup CurrenBuildTarget
{
get
{
string[] strs = System.Environment.GetCommandLineArgs();
foreach (string str in strs)
{
if (str.StartsWith("type"))
{
string stra = str.Replace("type=", "");
switch (stra)
{
case "AND":
return BuildTargetGroup.Android;
case "IOS":
return BuildTargetGroup.iOS;
default:
return BuildTargetGroup.Android;
}
}
}
return BuildTargetGroup.Android;
}
}
private static string mDefVersion = "9.0.0";
public static string version
{
get
{
string[] strs = System.Environment.GetCommandLineArgs();
foreach (string str in strs)
{
if (str.StartsWith("version"))
{
return str.Replace("version=", "");
}
}
return mDefVersion;
}
}
private static string mInstallVersion = "1.0.0";
public static string InstallVersion
{
get
{
string[] strs = System.Environment.GetCommandLineArgs();
foreach (string str in strs)
{
if (str.StartsWith("InstallVersion"))
{
return str.Replace("InstallVersion=", "");
}
}
return mInstallVersion;
}
}
/// <summary>
/// 获取资源版本号
/// </summary>
/// <returns></returns>
public static string Getversion(string resName)
{
return version;
}
private static bool misPublic = false;
/// <summary>
/// 是否是发布版本
/// </summary>
public static bool isPublic
{
get
{
string[] strs = System.Environment.GetCommandLineArgs();
foreach (string str in strs)
{
if (str.StartsWith("ispublic"))
{
return bool.Parse(str.Replace("ispublic=", ""));
}
}
return misPublic;
}
}
/// <summary>
/// 生成到到路径
/// </summary>
/// <value>The outpath.</value>
static string outpath
{
get
{
string[] strs = System.Environment.GetCommandLineArgs();
foreach (string str in strs)
{
if (str.StartsWith("outpath"))
{
return str.Replace("outpath=", "");
}
}
string url = Path.GetFullPath(Application.dataPath + "/../Release");
#if UNITY_IOS
return url+"/pro";
#elif UNITY_ANDROID
return url + "/1.apk";
#else
return url +"/1.exe";
#endif
}
}
public enum ChannelType
{
Other = 1,
AppStore,
}
public enum CollectionType
{
DSMJ = 8002,
SQMJ = 8003,
PXMJ = 8004,
TEST = 1001,
}
static bool Trans
{
get
{
string[] strs = System.Environment.GetCommandLineArgs();
foreach (string str in strs)
{
if (str.StartsWith("Trans"))
{
string channelStr = str.Replace("Trans=", "");
return bool.Parse(channelStr);
}
}
return false;
}
}
static CollectionType currentCollection
{
get
{
string[] strs = System.Environment.GetCommandLineArgs();
foreach (string str in strs)
{
if (str.StartsWith("Collection"))
{
string channelStr = str.Replace("Collection=", "");
CollectionType type =(CollectionType)Enum.Parse(typeof(CollectionType), channelStr);
return type;
}
}
return CollectionType.TEST;
}
}
/// <summary>
/// 渠道类型
/// </summary>
static int Channel
{
get
{
string[] strs = System.Environment.GetCommandLineArgs();
foreach (string str in strs)
{
if (str.StartsWith("channel"))
{
string channelStr = str.Replace("channel=", "");
if(channelStr == "Other")
{
return (int)ChannelType.Other;
}
else if (channelStr == "AppStore")
{
return (int)ChannelType.AppStore;
}
}
}
return (int)ChannelType.Other;
}
}
public static void ClearLuaFiles()
{
//ToLuaMenu.ClearLuaFiles();
}
public static void GenLuaAll()
{
//ToLuaMenu.GenLuaAll();
}
//[UnityEditor.MenuItem("Tools/bulid")]
public static void BuildProjected()
{
Debug.LogError("生成AB");
string assetName = Trans ? (int)currentCollection + "Trans" : (int)currentCollection+"";
assetName += ".asset";
//BuildCollectionResInfo builfCfg = null;
string buildCfgpath = "Assets/YKFramwork/Editor/BuildAbInfo/Collections/"
+ assetName;
Debug.Log("生成ab完成");
Debug.Log("准备生成APK");
//BuildAB.BuildAb();
if (CurrenBuildTarget == BuildTargetGroup.Android)
{
BuildForAndroid();
}
else if (CurrenBuildTarget == BuildTargetGroup.iOS)
{
BuildForIos();
}
else if (CurrenBuildTarget == BuildTargetGroup.Standalone)
{
}
}
public static void DelectDir(string srcPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo) //判断是否文件夹
{
DirectoryInfo subdir = new DirectoryInfo(i.FullName);
subdir.Delete(true); //删除子目录和文件
}
else
{
File.Delete(i.FullName); //删除指定文件
}
}
}
catch (Exception e)
{
throw;
}
}
[MenuItem("Tools/Test")]
public static void BuildDSMJ()
{
Debug.LogError(GetBuildScenes);
//mBuildHall = true;
//mIsBuilddsmj = true;
// string path = "Assets/YKFramwork/Editor/BuildAbInfo/Collections/" + 8002 + ".asset";
// BuildCollectionResInfo builfCfg = AssetDatabase.LoadAssetAtPath<BuildCollectionResInfo>(path);
// SetUmengXinXI(builfCfg);
}
public static void BuildForAndroid()
{
Debug.LogError("BuildForAndroid>>start");
PlayerSettings.Android.useAPKExpansionFiles = false;
PlayerSettings.Android.keystoreName = Application.dataPath + "/../xlkj.keystore";
PlayerSettings.Android.keyaliasPass = "xlkj13nk";
PlayerSettings.Android.keystorePass = "xlkj13nk";
PlayerSettings.Android.keyaliasName = "yanshi";
//PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, buildInfo.AndroidPackageName);
string[] scenes = null;
// if (buildInfo.isTrans)
// {
// scenes = GetTransBuildScenes;
// PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
// }
// else
{
scenes = GetBuildScenes;
PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevel22;
}
string res = BuildPipeline.BuildPlayer(scenes, outpath, BuildTarget.Android, BuildOptions.None);
Debug.Log("生成完成"+ res);
Debug.LogError("BuildForAndroid>>end");
}
#region 设置xml信息
public static void SetUPushMainnifestxml()
{
// string mainnifestRoot = Application.dataPath + "/Plugins/Android/push.plugin/AndroidManifest.xml";
// string mainnifestMode = Application.dataPath + "/../AndroidXMLMode/UpushManifest.xml";
//
// string mainnifestxml = File.ReadAllText(mainnifestMode);
// Debug.LogError("SetUPushMainnifestxml-> mainnifestxml="+ mainnifestxml);
// mainnifestxml = mainnifestxml
// .Replace("${applicationId}", buildInfo.AndroidPackageName);
//
// Debug.LogError("SetUPushMainnifestxml-> Replace =" + mainnifestxml);
//
// File.WriteAllText(mainnifestRoot, mainnifestxml);
}
public static void SetBaseMainnifestXml()
{
// string appid = WXConstant.UMengAppID[buildInfo.CollectionID];
// string Secret = WXConstant.UMengPushSecret[buildInfo.CollectionID];
// string channelstr = ((ChannelType)Channel).ToString();
// string mainnifestRoot = Application.dataPath + "/Plugins/Android/AndroidManifest.xml";
// string mainnifestMode = Application.dataPath + "/../AndroidXMLMode/AndroidManifest.xml";
// string mainnifestxml = File.ReadAllText(mainnifestMode);
// mainnifestxml = mainnifestxml.Replace("#packageName#", buildInfo.AndroidPackageName)
// .Replace("#UMENG_APPKEY", appid)
// .Replace("#UMENG_MESSAGE_SECRET", Secret)
// .Replace("#UMENG_CHANNEL", channelstr)
// .Replace("#JUMPALIPAYSCHEME", buildInfo.jumpScheme);
// File.WriteAllText(mainnifestRoot, mainnifestxml);
}
#endregion
#region 设置umeng信息
private class UMConstantInfo
{
public string appid;
public string secret;
public string channelid;// = channelstr
}
public static void SetUmengXinXI()
{
// string appid = WXConstant.UMengAppID[buildInfo.CollectionID];
// string Secret = WXConstant.UMengPushSecret[buildInfo.CollectionID];
// string channelstr = ((ChannelType)Channel).ToString();
// UMConstantInfo uMConstantInfo = new UMConstantInfo();
// uMConstantInfo.appid = appid;
// uMConstantInfo.secret = Secret;
// uMConstantInfo.channelid = channelstr;
// string json= JsonUtility.ToJson(uMConstantInfo);
// File.WriteAllText(Application.streamingAssetsPath + "/UMConstant.json", json);
}
#endregion
public static void BuildForIos()
{
string assetName = (int)currentCollection + "";
// if (buildCfg.isTrans)
// {
// assetName += "Trans";
// }
// else
// {
// if(Channel == (int)ChannelType.AppStore)
// {
// assetName += "Appstore";
// }
// }
PlayerSettings.SetScriptingBackend(BuildTargetGroup.iOS, ScriptingImplementation.IL2CPP);
PlayerSettings.SetArchitecture(BuildTargetGroup.iOS, 2);
// if (Channel == (int)ChannelType.AppStore)
// {
// PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, buildCfg.IOSAppStorePackName);
// }
// else
// {
// PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, buildCfg.IOSPackName);
// }
PlayerSettings.iOS.appInBackgroundBehavior = iOSAppInBackgroundBehavior.Custom;
PlayerSettings.iOS.backgroundModes = iOSBackgroundMode.Audio|iOSBackgroundMode.RemoteNotification;
string[] scenes = null;
scenes = GetBuildScenes;
#if UNITY_IOS
PlayerPrefs.SetString(XcodeProjectUpdater.SETTING_DATA_PATHKEY, "Assets/YKFramwork/Editor/AutoBuild/" + assetName);
PlayerSettings.iOS.allowHTTPDownload = true;
PlayerSettings.iOS.appleEnableAutomaticSigning = false;
string res = BuildPipeline.BuildPlayer(scenes, outpath, BuildTarget.iOS, BuildOptions.None);
#endif
}
/// <summary>
/// 设置背景图和icon
/// </summary>
/// <param name="collectionID">合集id</param>
//[MenuItem("Tools/setIcon")]
public static void SetIconAndBg()
{
string[] strs = System.Environment.GetCommandLineArgs();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine(Channel.ToString());
sb.AppendLine(isPublic.ToString());
File.WriteAllText(Application.dataPath + "/Resources/buildversioninfo.bytes", sb.ToString());
PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
PlayerSettings.bundleVersion = InstallVersion;
PlayerSettings.SplashScreen.show = false;
PlayerSettings.stripEngineCode = false;
PlayerSettings.defaultInterfaceOrientation = UIOrientation.AutoRotation;
PlayerSettings.allowedAutorotateToLandscapeLeft = true;
PlayerSettings.allowedAutorotateToLandscapeRight = true;
PlayerSettings.allowedAutorotateToPortrait = false;
PlayerSettings.allowedAutorotateToPortraitUpsideDown = false;
PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, true);
PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.iOS, true);
string root = Application.dataPath +"/CollectionEeefctRes";
// Texture2D icon = AssetDatabase.LoadAssetAtPath<Texture2D>(FileUtil.GetProjectRelativePath(iconRoot));
// Texture2D[] androidIcons = new Texture2D[6];
// for (int i = 0; i < androidIcons.Length; i++)
// {
// androidIcons[i] = icon;
// }
// Texture2D[] iosIcons = new Texture2D[18];
// for (int i = 0;i< iosIcons.Length;i++)
// {
// iosIcons[i] = icon;
// }
// Texture2D[] pcIcons = new Texture2D[7];
// for (int i = 0;i< pcIcons.Length;i++)
// {
// pcIcons[i] = icon;
// }
//AssetDatabase.CopyAsset()
//PlayerSettings.productName = buildInfo.CollectionName;
PlayerSettings.companyName = "游客学院";
// PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Standalone, pcIcons);
// PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, androidIcons);
// PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.iOS, iosIcons);
AssetDatabase.Refresh();
}
}