70 lines
2.5 KiB
C#
70 lines
2.5 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEditor;
|
|||
|
using System.IO;
|
|||
|
using System;
|
|||
|
//using System.Diagnostics;
|
|||
|
/// <summary>
|
|||
|
/// 安卓打包(接口都由python外部通过cmd命令调用)
|
|||
|
/// </summary>
|
|||
|
public class CommandBuilder : EditorWindow
|
|||
|
{
|
|||
|
|
|||
|
public static void BuildData()
|
|||
|
{
|
|||
|
GameEditor.Core.DataConfig.ConfigExportWindow.PyCallBuildData();
|
|||
|
}
|
|||
|
//打包资源和热更代码
|
|||
|
public static void BuildAssets()
|
|||
|
{
|
|||
|
//打包游戏
|
|||
|
GameEditor.FrameTool.FrameTool.BuildGameAssetBundles();
|
|||
|
//拷贝AssetBundle到流媒体目录
|
|||
|
GameEditor.FrameTool.FrameTool.CopyAssetBundleToStreamingAssets();
|
|||
|
//刷新资源配置
|
|||
|
GameEditor.ResourcesPathEditor.CreateResourcePathConfig();
|
|||
|
}
|
|||
|
|
|||
|
public static void BuildAS()
|
|||
|
{
|
|||
|
string[] s = System.Environment.GetCommandLineArgs();//获取命令行参数
|
|||
|
//----------设置config文件-----------------
|
|||
|
|
|||
|
int index = s.Length - 1;
|
|||
|
string str = s[index];
|
|||
|
string[]arr = str.Split('#');
|
|||
|
string targetPath = Application.dataPath + "/Resources/version.txt";
|
|||
|
string _str = System.Environment.CurrentDirectory.Replace('\\', '/');
|
|||
|
string copyPath = _str + "/AssetBundles/" + arr[0];
|
|||
|
if (File.Exists(targetPath))
|
|||
|
{
|
|||
|
File.Delete(targetPath);
|
|||
|
}
|
|||
|
File.Copy(copyPath, targetPath, true);
|
|||
|
//----------设置打包场景准备导出android-----------------
|
|||
|
PlayerSettings.productName = "ex_android_jl";
|
|||
|
//设置是否导出obb
|
|||
|
PlayerSettings.Android.useAPKExpansionFiles = arr[2] == "1";
|
|||
|
|
|||
|
string outPath = "D:/exAndroid/unity_ex_as";
|
|||
|
if (Directory.Exists(outPath + "/ex_android_jl"))
|
|||
|
{
|
|||
|
Directory.Delete(outPath + "/ex_android_jl/", true);
|
|||
|
}
|
|||
|
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
|||
|
// 设置需要打包的场景
|
|||
|
string launchScene = arr[1];
|
|||
|
Debug.Log("打包场景:" + launchScene);
|
|||
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
|
|||
|
buildPlayerOptions.locationPathName = outPath;
|
|||
|
buildPlayerOptions.options = BuildOptions.None;
|
|||
|
buildPlayerOptions.options |= BuildOptions.AcceptExternalModificationsToPlayer;
|
|||
|
buildPlayerOptions.scenes = new[] { launchScene };
|
|||
|
buildPlayerOptions.target = BuildTarget.Android;
|
|||
|
// 调用开始打包
|
|||
|
BuildPipeline.BuildPlayer(buildPlayerOptions);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|