201 lines
6.0 KiB
C#
201 lines
6.0 KiB
C#
|
using System;
|
||
|
using System.IO;
|
||
|
using UnityEditor;
|
||
|
using UnityEngine;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 批处理模式
|
||
|
/// </summary>
|
||
|
internal class BatchBuild
|
||
|
{
|
||
|
private static string outputPath = "{0}/{1}{2}";
|
||
|
private static string pathSuffix = "";
|
||
|
|
||
|
public static void BuildContentAndPlayer()
|
||
|
{
|
||
|
Init();
|
||
|
|
||
|
//Build BuildPlayer
|
||
|
var buildOptions = BuildOptions.None;
|
||
|
if (EditorUserBuildSettings.development)
|
||
|
buildOptions |= BuildOptions.Development;
|
||
|
|
||
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
|
||
|
{
|
||
|
scenes = GetScenes(),
|
||
|
locationPathName = string.Format(outputPath, AddressableBuildBase.BuildParam.BuildPath,
|
||
|
AddressableBuildBase.BuildParam.BuildName, pathSuffix),
|
||
|
options = buildOptions,
|
||
|
target = EditorUserBuildSettings.activeBuildTarget,
|
||
|
targetGroup = BuildPipeline.GetBuildTargetGroup(AddressableBuildBase.BuildParam.BuildTargetPlatform),
|
||
|
};
|
||
|
AddressableBuildBase.BuildContentAndPlayer(buildPlayerOptions);
|
||
|
}
|
||
|
|
||
|
public static void BuildAddressable()
|
||
|
{
|
||
|
Init();
|
||
|
//ApplyPlayerSetting();
|
||
|
AddressableBuildBase.BuildAddressable();
|
||
|
}
|
||
|
|
||
|
public static void UpdatePreviousBuild()
|
||
|
{
|
||
|
Init();
|
||
|
//ApplyPlayerSetting();
|
||
|
AddressableBuildBase.UpdatePreviousBuild();
|
||
|
}
|
||
|
|
||
|
//构建前相关设置
|
||
|
public static bool ApplyPlayerSetting()
|
||
|
{
|
||
|
BuildUtils.SetFileReadable(Application.dataPath + "/AddressableAssetsData/AssetGroups");
|
||
|
BuildUtils.SetFileReadable(Application.dataPath.Replace("/Assets",
|
||
|
"/ProjectSettings/ScriptableBuildPipeline.json"));
|
||
|
|
||
|
GetPlayerSettingsParams();
|
||
|
AddressableBuildBase.ApplyPlayerSettings();
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//构建时相关参数
|
||
|
private static bool Init()
|
||
|
{
|
||
|
AutoGenSettings();
|
||
|
GetBuildSettingParams();
|
||
|
GenBuildPathSuffix();
|
||
|
AddressableBuildBase.ApplyBuildSettings();
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
private static void AutoGenSettings()
|
||
|
{
|
||
|
PlayerSettings.keystorePass = "phxh123456";
|
||
|
PlayerSettings.keyaliasPass = "phxh123456";
|
||
|
}
|
||
|
|
||
|
private static string[] GetScenes()
|
||
|
{
|
||
|
var scenes = EditorBuildSettings.scenes;
|
||
|
if (scenes != null && scenes.Length > 0)
|
||
|
{
|
||
|
var scenesName = new string[scenes.Length];
|
||
|
for (int i = 0; i < scenes.Length; i++)
|
||
|
{
|
||
|
scenesName[i] = scenes[i].path;
|
||
|
}
|
||
|
|
||
|
return scenesName;
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
private static void GetPlayerSettingsParams()
|
||
|
{
|
||
|
var args = Environment.GetCommandLineArgs();
|
||
|
|
||
|
for (var i = 0; i < args.Length; i++)
|
||
|
switch (args[i])
|
||
|
{
|
||
|
case "-platform":
|
||
|
JudgmentPlatform(args[i + 1]);
|
||
|
break;
|
||
|
case "-appVersion":
|
||
|
AddressableBuildBase.BuildParam.AppVersion = args[i + 1];
|
||
|
break;
|
||
|
case "-appName":
|
||
|
AddressableBuildBase.BuildParam.AppName = args[i + 1];
|
||
|
break;
|
||
|
case "-developmentBuild":
|
||
|
AddressableBuildBase.BuildParam.DevelopmentBuild = BuildUtils.ConvertBool(args[i + 1]);
|
||
|
break;
|
||
|
case "-aab":
|
||
|
AddressableBuildBase.BuildParam.BuildAab = BuildUtils.ConvertBool(args[i + 1]);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
private static void GetBuildSettingParams()
|
||
|
{
|
||
|
var args = Environment.GetCommandLineArgs();
|
||
|
|
||
|
for (var i = 0; i < args.Length; i++)
|
||
|
switch (args[i])
|
||
|
{
|
||
|
case "-buildName":
|
||
|
AddressableBuildBase.BuildParam.BuildName = args[i + 1];
|
||
|
break;
|
||
|
case "appVersion":
|
||
|
AddressableBuildBase.BuildParam.AppVersion = args[i + 1];
|
||
|
break;
|
||
|
case "-outpath":
|
||
|
{
|
||
|
Directory.CreateDirectory(args[i + 1]);
|
||
|
AddressableBuildBase.BuildParam.BuildPath = args[i + 1];
|
||
|
break;
|
||
|
}
|
||
|
case "-profile":
|
||
|
AddressableBuildBase.BuildParam.ProfileID = args[i + 1];
|
||
|
break;
|
||
|
case "-channel":
|
||
|
AddressableBuildBase.BuildParam.WorkSpace = args[i + 1];
|
||
|
break;
|
||
|
case "-clearCached":
|
||
|
{
|
||
|
AddressableBuildBase.BuildParam.ClearCached = BuildUtils.ConvertBool(args[i + 1]);
|
||
|
break;
|
||
|
}
|
||
|
case "-groups":
|
||
|
AddressableBuildBase.BuildParam.Groups = args[i + 1].Split(",");
|
||
|
break;
|
||
|
case "-enableHotUpdate":
|
||
|
AddressableBuildBase.BuildParam.EnableHotUpdate = BuildUtils.ConvertBool(args[i + 1]);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static void GenBuildPathSuffix()
|
||
|
{
|
||
|
var platform = EditorUserBuildSettings.activeBuildTarget;
|
||
|
switch (platform)
|
||
|
{
|
||
|
case BuildTarget.iOS:
|
||
|
{
|
||
|
pathSuffix = "";
|
||
|
break;
|
||
|
}
|
||
|
default:
|
||
|
{
|
||
|
if (EditorUserBuildSettings.buildAppBundle)
|
||
|
{
|
||
|
pathSuffix = ".aab";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
pathSuffix = ".apk";
|
||
|
}
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static void JudgmentPlatform(string platform)
|
||
|
{
|
||
|
switch (platform)
|
||
|
{
|
||
|
case "iOS":
|
||
|
{
|
||
|
AddressableBuildBase.BuildParam.BuildTargetPlatform = BuildTarget.iOS;
|
||
|
break;
|
||
|
}
|
||
|
default:
|
||
|
{
|
||
|
AddressableBuildBase.BuildParam.BuildTargetPlatform = BuildTarget.Android;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|