modify
This commit is contained in:
parent
44d70ebf32
commit
6dea74ee0f
3
Client/Assets/Editor/BuildCLI.meta
Normal file
3
Client/Assets/Editor/BuildCLI.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 69ea7963a8cfa4645b9345e57aef8331
|
||||||
|
timeCreated: 1737867267
|
||||||
98
Client/Assets/Editor/BuildCLI/AppBuildHelper.cs
Normal file
98
Client/Assets/Editor/BuildCLI/AppBuildHelper.cs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using AlicizaX.Editor;
|
||||||
|
using AlicizaX;
|
||||||
|
using AlicizaX.Debugger.Runtime;
|
||||||
|
using AlicizaX.Framework.Runtime.ABase;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public static class AppBuildHelper
|
||||||
|
{
|
||||||
|
public static void GeneratAppBuilderSetting(string language, DebuggerActiveWindowType debugMode, int resMode)
|
||||||
|
{
|
||||||
|
const string AppBuilderSettingPath = "Assets/Resources/ModuleDynamicBindInfo.bytes";
|
||||||
|
ModuleDynamicBindInfo appBuilderSetting = new ModuleDynamicBindInfo();
|
||||||
|
appBuilderSetting.Language = language;
|
||||||
|
appBuilderSetting.DebuggerActiveWindowType = debugMode;
|
||||||
|
appBuilderSetting.ResMode = resMode;
|
||||||
|
File.WriteAllText(AppBuilderSettingPath, Utility.Json.ToJson(appBuilderSetting));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void BuildApplication(AppBuildParameter appBuildParameter, bool showExplorer = false)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(appBuildParameter.OutPutPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(appBuildParameter.OutPutPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Log("Starting build application");
|
||||||
|
|
||||||
|
GeneratAppBuilderSetting(appBuildParameter.Language, appBuildParameter.ShowDebugWnd, appBuildParameter.ResMode);
|
||||||
|
|
||||||
|
Debug.Log("Generate AppBuilderSetting.bytes");
|
||||||
|
|
||||||
|
PlayerSettings.fullScreenMode = appBuildParameter.FullScreenMode;
|
||||||
|
if (appBuildParameter.FullScreenMode == FullScreenMode.Windowed)
|
||||||
|
{
|
||||||
|
PlayerSettings.defaultScreenWidth = appBuildParameter.WindowedScreenSize.x;
|
||||||
|
PlayerSettings.defaultScreenHeight = appBuildParameter.WindowedScreenSize.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(appBuildParameter.Version))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var options = new BuildPlayerOptions
|
||||||
|
{
|
||||||
|
scenes = appBuildParameter.Scenes,
|
||||||
|
locationPathName = Path.Combine(appBuildParameter.OutPutPath, appBuildParameter.FileName),
|
||||||
|
target = appBuildParameter.BuildTarget,
|
||||||
|
options = appBuildParameter.DevelopBuild ? BuildOptions.Development : BuildOptions.None
|
||||||
|
};
|
||||||
|
|
||||||
|
var report = BuildPipeline.BuildPlayer(options);
|
||||||
|
HandleBuildReport(report);
|
||||||
|
if (showExplorer)
|
||||||
|
{
|
||||||
|
DirectoryInfo directoryInfo = Directory.GetParent(report.summary.outputPath);
|
||||||
|
if (directoryInfo != null) OpenFolder.Execute(directoryInfo.FullName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Log($"构建过程中发生异常: {e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void HandleBuildReport(UnityEditor.Build.Reporting.BuildReport report)
|
||||||
|
{
|
||||||
|
if (report.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded)
|
||||||
|
{
|
||||||
|
Debug.Log($"整包构建完成:${report.summary.outputPath}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if UNITY_2023_1_OR_NEWER
|
||||||
|
Debug.LogError(report.SummarizeErrors());
|
||||||
|
#else
|
||||||
|
var errors = new List<string>();
|
||||||
|
foreach (var step in report.steps)
|
||||||
|
{
|
||||||
|
foreach (var msg in step.messages)
|
||||||
|
{
|
||||||
|
if (msg.type == LogType.Error || msg.type == LogType.Exception)
|
||||||
|
{
|
||||||
|
errors.Add($"[Step: {step.name}] {msg.content}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Debug.LogError($"构建失败,错误信息:\n{string.Join("\n", errors)}");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Client/Assets/Editor/BuildCLI/AppBuildHelper.cs.meta
Normal file
3
Client/Assets/Editor/BuildCLI/AppBuildHelper.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 154ce1f8cc3455246af4a6501d246f02
|
||||||
|
timeCreated: 1740128549
|
||||||
83
Client/Assets/Editor/BuildCLI/BuildParameter.cs
Normal file
83
Client/Assets/Editor/BuildCLI/BuildParameter.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using System;
|
||||||
|
using AlicizaX;
|
||||||
|
using AlicizaX.Debugger.Runtime;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
using YooAsset;
|
||||||
|
using YooAsset.Editor;
|
||||||
|
|
||||||
|
|
||||||
|
public class AppBuildParameter
|
||||||
|
{
|
||||||
|
public BuildTarget BuildTarget;
|
||||||
|
public string OutPutPath;
|
||||||
|
public DebuggerActiveWindowType ShowDebugWnd;
|
||||||
|
public bool DevelopBuild;
|
||||||
|
public int ResMode;
|
||||||
|
public string FileName;
|
||||||
|
public string Language;
|
||||||
|
public string[] Scenes;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 版本
|
||||||
|
/// </summary>
|
||||||
|
public string Version;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否全屏
|
||||||
|
/// </summary>
|
||||||
|
public FullScreenMode FullScreenMode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 窗口化大小
|
||||||
|
/// </summary>
|
||||||
|
public Vector2Int WindowedScreenSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class ResourceBuildParameter
|
||||||
|
{
|
||||||
|
public BuildTarget ResourceBuildTarget;
|
||||||
|
public string PackageVersion;
|
||||||
|
public bool UseDefaultPackageVersion;
|
||||||
|
public string OutputPath;
|
||||||
|
public ResourceBuildMode BuildMode;
|
||||||
|
|
||||||
|
public ECompressOption CompressOption = ECompressOption.LZ4;
|
||||||
|
public EFileNameStyle FileNameStyle = EFileNameStyle.BundleName_HashName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从文件头里剥离Unity版本信息
|
||||||
|
/// </summary>
|
||||||
|
public bool StripUnityVersion = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
||||||
|
/// </summary>
|
||||||
|
public bool DisableWriteTypeTree = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 忽略类型树变化(无效参数)
|
||||||
|
/// </summary>
|
||||||
|
public bool IgnoreTypeTreeChanges = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 使用可寻址地址代替资源路径
|
||||||
|
/// 说明:开启此项可以节省运行时清单占用的内存!
|
||||||
|
/// </summary>
|
||||||
|
public bool ReplaceAssetPathWithAddress = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自动建立资源对象对图集的依赖关系
|
||||||
|
/// </summary>
|
||||||
|
public bool TrackSpriteAtlasDependencies = false;
|
||||||
|
|
||||||
|
public string EncryptionServiceType = "AlicizaX.Resource.Editor.FileOffsetEncryption";
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ResourceBuildMode
|
||||||
|
{
|
||||||
|
Offline,
|
||||||
|
Online,
|
||||||
|
}
|
||||||
3
Client/Assets/Editor/BuildCLI/BuildParameter.cs.meta
Normal file
3
Client/Assets/Editor/BuildCLI/BuildParameter.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4d5b605d55cc82844b76260841f92475
|
||||||
|
timeCreated: 1741577226
|
||||||
135
Client/Assets/Editor/BuildCLI/ResourceBuildHelper.cs
Normal file
135
Client/Assets/Editor/BuildCLI/ResourceBuildHelper.cs
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using YooAsset;
|
||||||
|
using YooAsset.Editor;
|
||||||
|
|
||||||
|
public static class ResourceBuildHelper
|
||||||
|
{
|
||||||
|
private const bool EnableSharePack = true;
|
||||||
|
private const string BuildPackageName = "DefaultPackage";
|
||||||
|
|
||||||
|
private static string GeneratePackageVersion()
|
||||||
|
{
|
||||||
|
int totalMinutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
|
||||||
|
return DateTime.Now.ToString("yyyy-MM-dd") + "-" + totalMinutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void BuildResourcePackage(ResourceBuildParameter buildParameter)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(buildParameter.OutputPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(buildParameter.OutputPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string copyParams = string.Empty;
|
||||||
|
EBuildinFileCopyOption copyOption = EBuildinFileCopyOption.None;
|
||||||
|
if (buildParameter.BuildMode == ResourceBuildMode.Online)
|
||||||
|
{
|
||||||
|
copyOption = EBuildinFileCopyOption.ClearAndCopyByTags;
|
||||||
|
copyParams = "Launch";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
copyOption = EBuildinFileCopyOption.ClearAndCopyAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
var parameters = new ScriptableBuildParameters
|
||||||
|
{
|
||||||
|
BuildOutputRoot = buildParameter.OutputPath,
|
||||||
|
BuildTarget = buildParameter.ResourceBuildTarget,
|
||||||
|
PackageName = BuildPackageName,
|
||||||
|
BuildBundleType = (int)EBuildBundleType.AssetBundle,
|
||||||
|
BuildPipeline = EBuildPipeline.ScriptableBuildPipeline.ToString(),
|
||||||
|
BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(),
|
||||||
|
PackageVersion = buildParameter.UseDefaultPackageVersion ? GeneratePackageVersion() : buildParameter.PackageVersion,
|
||||||
|
CompressOption = buildParameter.CompressOption,
|
||||||
|
BuiltinShadersBundleName = GetBuiltinShaderBundleName(),
|
||||||
|
VerifyBuildingResult = true,
|
||||||
|
ClearBuildCacheFiles = false,
|
||||||
|
BuildinFileCopyOption = copyOption,
|
||||||
|
BuildinFileCopyParams = copyParams,
|
||||||
|
EnableSharePackRule = EnableSharePack,
|
||||||
|
FileNameStyle = buildParameter.FileNameStyle,
|
||||||
|
EncryptionServices = CreateEncryptionInstance(buildParameter.EncryptionServiceType),
|
||||||
|
ReplaceAssetPathWithAddress = buildParameter.ReplaceAssetPathWithAddress,
|
||||||
|
StripUnityVersion = buildParameter.StripUnityVersion,
|
||||||
|
DisableWriteTypeTree = buildParameter.DisableWriteTypeTree,
|
||||||
|
IgnoreTypeTreeChanges = buildParameter.IgnoreTypeTreeChanges,
|
||||||
|
TrackSpriteAtlasDependencies = buildParameter.TrackSpriteAtlasDependencies,
|
||||||
|
};
|
||||||
|
|
||||||
|
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline();
|
||||||
|
var report = pipeline.Run(parameters, true);
|
||||||
|
|
||||||
|
if (report.Success)
|
||||||
|
{
|
||||||
|
// if (_copyAfterBuild && !string.IsNullOrEmpty(_copyDestination))
|
||||||
|
// {
|
||||||
|
// CopyFiles(report.OutputPackageDirectory, _copyDestination);
|
||||||
|
// }
|
||||||
|
Debug.Log($"AB包构建完成!\n输出目录: {report.OutputPackageDirectory}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log($"错误信息: {report.ErrorInfo}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 内置着色器资源包名称
|
||||||
|
/// 注意:和自动收集的着色器资源包名保持一致!
|
||||||
|
/// </summary>
|
||||||
|
private static string GetBuiltinShaderBundleName()
|
||||||
|
{
|
||||||
|
var uniqueBundleName = AssetBundleCollectorSettingData.Setting.UniqueBundleName;
|
||||||
|
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||||
|
return packRuleResult.GetBundleName(BuildPackageName, uniqueBundleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CopyFiles(string source, string destination)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(destination))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(destination);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string file in Directory.GetFiles(source))
|
||||||
|
{
|
||||||
|
File.Copy(file, Path.Combine(destination, Path.GetFileName(file)), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Log($"文件拷贝完成: {source} -> {destination}");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError($"文件拷贝失败: {e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEncryptionServices CreateEncryptionInstance(string encryptionService)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(encryptionService)) return null;
|
||||||
|
|
||||||
|
var type = Type.GetType(encryptionService);
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
return (IEncryptionServices)Activator.CreateInstance(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d0418e1e75999064ca53a72ff542a08c
|
||||||
|
timeCreated: 1740128311
|
||||||
@ -3,15 +3,13 @@
|
|||||||
"rootNamespace": "SAOL1.Editor",
|
"rootNamespace": "SAOL1.Editor",
|
||||||
"references": [
|
"references": [
|
||||||
"GUID:8d62da4aabd2a19419c7378d23ea5849",
|
"GUID:8d62da4aabd2a19419c7378d23ea5849",
|
||||||
"GUID:75b6f2078d190f14dbda4a5b747d709c",
|
|
||||||
"GUID:a19b414bea3b97240a91aeab9a8eab36",
|
|
||||||
"GUID:99a2a63c2a1143c4ba448165a98a5108",
|
"GUID:99a2a63c2a1143c4ba448165a98a5108",
|
||||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||||
"GUID:4d1926c9df5b052469a1c63448b7609a",
|
"GUID:4d1926c9df5b052469a1c63448b7609a",
|
||||||
"GUID:acfef7cabed3b0a42b25edb1cd4fa259",
|
|
||||||
"GUID:2373f786d14518f44b0f475db77ba4de",
|
"GUID:2373f786d14518f44b0f475db77ba4de",
|
||||||
"GUID:82bdcc42401007348aadb37dd5adc131",
|
"GUID:82bdcc42401007348aadb37dd5adc131",
|
||||||
"GUID:1619e00706139ce488ff80c0daeea8e7"
|
"GUID:1619e00706139ce488ff80c0daeea8e7",
|
||||||
|
"GUID:fb064c8bf96bac94e90d2f39090daa94"
|
||||||
],
|
],
|
||||||
"includePlatforms": [
|
"includePlatforms": [
|
||||||
"Editor"
|
"Editor"
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit 28036786c8ddfe5be745e698746f3673e6cb2985
|
Subproject commit d124be0855fb459853b8dac3f9e2d7bf123b03d8
|
||||||
Loading…
Reference in New Issue
Block a user