| | |
| | | }
|
| | |
|
| | | public static VersionConfig versionConfig1 = null;
|
| | |
|
| | | /// <summary>
|
| | | /// 导出Android工程给AS打包
|
| | | /// Unity只负责导出unityLibrary,SDK/Gradle/签名等均由AS工程处理
|
| | | /// </summary>
|
| | | public static void ExportAndroidProject(string _publisher, int _buildIndex, bool _development, string _outputPath, string _assetBundlePath)
|
| | | {
|
| | | PreBuild(_publisher, _buildIndex);
|
| | |
|
| | | var versionName = string.Empty;
|
| | | var versionConfig = GetVersionConfig(_publisher, out versionName);
|
| | |
|
| | | PlayerSettings.Android.bundleVersionCode = VersionConfig.GetVersionNumber(versionConfig.version);
|
| | | PlayerSettings.enableInternalProfiler = _development;
|
| | |
|
| | | // 先清理StreamingAssets,再从AssetBundles目录拷贝资源到StreamingAssets
|
| | | // 这样BuildPlayer导出工程时才会包含游戏资源
|
| | | var streamingPath = ResourcesPath.Instance.StreamingAssetPath;
|
| | | if (Directory.Exists(streamingPath))
|
| | | Directory.Delete(streamingPath, true);
|
| | |
|
| | | if (!string.IsNullOrEmpty(_assetBundlePath) && Directory.Exists(_assetBundlePath))
|
| | | {
|
| | | var files = new List<FileInfo>();
|
| | | FileExtersion.GetAllDirectoryFileInfos(_assetBundlePath, files);
|
| | | foreach (var file in files)
|
| | | {
|
| | | var extension = Path.GetExtension(file.FullName);
|
| | | if (extension == ".meta")
|
| | | continue;
|
| | |
|
| | | var relativePath = FileExtersion.GetFileRelativePath(_assetBundlePath, file.FullName);
|
| | | if (relativePath.StartsWith("patch"))
|
| | | continue;
|
| | |
|
| | | var to = StringUtility.Concat(streamingPath, relativePath);
|
| | | var directory = Path.GetDirectoryName(to);
|
| | | if (!Directory.Exists(directory))
|
| | | Directory.CreateDirectory(directory);
|
| | |
|
| | | File.Copy(file.FullName, to, true);
|
| | | }
|
| | | Debug.LogFormat("资源拷贝完成,从 {0} 到 {1}", _assetBundlePath, streamingPath);
|
| | | }
|
| | | else
|
| | | {
|
| | | Debug.LogWarningFormat("AssetBundle路径为空或不存在: {0},导出工程将不包含游戏资源", _assetBundlePath);
|
| | | }
|
| | |
|
| | | // 清理Unity端旧的Android插件文件,避免导出工程时带入SDK相关文件(由AS处理)
|
| | | if (Directory.Exists(THE_2TH_WORLD_SDK_PATH))
|
| | | Directory.Delete(THE_2TH_WORLD_SDK_PATH, true);
|
| | | if (File.Exists(MANIFEST_PATH))
|
| | | File.Delete(MANIFEST_PATH);
|
| | | if (File.Exists(File_baseProjectTemplate))
|
| | | File.Delete(File_baseProjectTemplate);
|
| | | if (File.Exists(File_google_services))
|
| | | File.Delete(File_google_services);
|
| | | if (File.Exists(File_gradleTemplate))
|
| | | File.Delete(File_gradleTemplate);
|
| | | if (File.Exists(File_LauncherManifest))
|
| | | File.Delete(File_LauncherManifest);
|
| | | if (File.Exists(File_launcherTemplate))
|
| | | File.Delete(File_launcherTemplate);
|
| | | if (File.Exists(File_mainTemplate))
|
| | | File.Delete(File_mainTemplate);
|
| | | if (File.Exists(File_deps))
|
| | | File.Delete(File_deps);
|
| | | if (File.Exists(File_huawei_services))
|
| | | File.Delete(File_huawei_services);
|
| | | if (File.Exists(File_settingGradle))
|
| | | File.Delete(File_settingGradle);
|
| | |
|
| | | AssetDatabase.SaveAssets();
|
| | | AssetDatabase.Refresh();
|
| | |
|
| | | // 关键设置:导出为Gradle工程而非直接打APK
|
| | | EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
| | | EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
|
| | |
|
| | | // 导出路径
|
| | | string outputDir = Path.Combine(_outputPath, versionName + "_" + versionConfig.clientPackageFlag);
|
| | |
|
| | | if (Directory.Exists(outputDir))
|
| | | {
|
| | | Directory.Delete(outputDir, true);
|
| | | }
|
| | |
|
| | | Debug.LogFormat("开始导出Android工程,输出路径: {0}", outputDir);
|
| | |
|
| | | BuildPipeline.BuildPlayer(baseLevels, outputDir, BuildTarget.Android,
|
| | | _development ? BuildOptions.AcceptExternalModificationsToPlayer | BuildOptions.Development | BuildOptions.AllowDebugging
|
| | | : BuildOptions.AcceptExternalModificationsToPlayer);
|
| | |
|
| | | Debug.LogFormat("导出Android工程完成!输出路径: {0}", outputDir);
|
| | | Debug.LogFormat("请将unityLibrary目录内容更新到AS工程中,然后在AS中进行打包");
|
| | |
|
| | | // 导出完成后恢复设置
|
| | | EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
|
| | | }
|
| | |
|
| | | public static void BuildIpa(string _sdkPath, string _publisher, int _buildIndex, bool _replace)
|
| | | {
|
| | | PreBuild(_publisher, _buildIndex);
|