Skip to content

Commit

Permalink
updated (yooasset)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Jan 8, 2024
1 parent 2cdf026 commit 0b6f82d
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async static UniTask InitSetup()
#region Init Preset Packages
bool appInitialized = await InitPresetAppPackages();
bool dlcInitialized = await InitPresetDlcPackages();
Logging.Print<Logger>($"<color=#ffe45a>{appInitialized} {dlcInitialized}</color>");
Logging.Print<Logger>($"<color=#ffe45a>appInitialized: {appInitialized}, dlcInitialized: {dlcInitialized}</color>");
isInitialized = dlcInitialized && appInitialized;
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ public void SetDependAssetInfos(List<BuildAssetInfo> dependAssetInfos)
}

/// <summary>
/// 设置为统一的着色器包名
/// 设置资源包名称
/// </summary>
public void SetShaderBundleName(string packageName, bool uniqueBundleName)
public void SetBundleName(string bundleName)
{
// 获取着色器打包规则结果
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
BundleName = shaderPackRuleResult.GetBundleName(packageName, uniqueBundleName);
if (HasBundleName())
throw new System.Exception("Should never get here !");

BundleName = bundleName;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public abstract class BuildParameters
public string PackageVersion;


/// <summary>
/// 是否启用共享资源打包
/// </summary>
public bool EnableSharePackRule = false;

/// <summary>
/// 验证构建结果
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ protected void CreateReportFile(BuildParametersContext buildParametersContext, B
buildReport.Summary.BuildMode = buildParameters.BuildMode;
buildReport.Summary.BuildPackageName = buildParameters.PackageName;
buildReport.Summary.BuildPackageVersion = buildParameters.PackageVersion;

// 收集器配置
buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName;
buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
buildReport.Summary.IgnoreDefaultType = buildMapContext.Command.IgnoreDefaultType;
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ?
"null" : buildParameters.EncryptionServices.GetType().FullName;

// 构建参数
buildReport.Summary.EnableSharePackRule = buildParameters.EnableSharePackRule;
buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ? "null" : buildParameters.EncryptionServices.GetType().FullName;
if (buildParameters.BuildPipeline == nameof(BuiltinBuildPipeline))
{
var builtinBuildParameters = buildParameters as BuiltinBuildParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,45 @@ public BuildMapContext CreateBuildMap(BuildParameters buildParameters)
// 6. 自动收集所有依赖的着色器
if (collectResult.Command.AutoCollectShaders)
{
// 获取着色器打包规则结果
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
string shaderBundleName = shaderPackRuleResult.GetBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
foreach (var buildAssetInfo in allBuildAssetInfos.Values)
{
if (buildAssetInfo.CollectorType == ECollectorType.None)
{
if (buildAssetInfo.AssetInfo.IsShaderAsset())
{
buildAssetInfo.SetShaderBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
buildAssetInfo.SetBundleName(shaderBundleName);
}
}
}
}

// 7. 记录关键信息
// 7. 计算共享资源的包名
if (buildParameters.EnableSharePackRule)
{
PreProcessPackShareBundle(buildParameters, collectResult.Command, allBuildAssetInfos);
foreach (var buildAssetInfo in allBuildAssetInfos.Values)
{
if (buildAssetInfo.HasBundleName() == false)
{
PackRuleResult packRuleResult = GetShareBundleName(buildAssetInfo);
if (packRuleResult.IsValid())
{
string shareBundleName = packRuleResult.GetShareBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
buildAssetInfo.SetBundleName(shareBundleName);
}
}
}
PostProcessPackShareBundle();
}

// 8. 记录关键信息
context.AssetFileCount = allBuildAssetInfos.Count;
context.Command = collectResult.Command;

// 8. 移除不参与构建的资源
// 9. 移除不参与构建的资源
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
foreach (var buildAssetInfo in allBuildAssetInfos.Values)
{
Expand All @@ -114,7 +136,7 @@ public BuildMapContext CreateBuildMap(BuildParameters buildParameters)
allBuildAssetInfos.Remove(removeValue.AssetInfo.AssetPath);
}

// 9. 构建资源列表
// 10. 构建资源列表
var allPackAssets = allBuildAssetInfos.Values.ToList();
if (allPackAssets.Count == 0)
{
Expand Down Expand Up @@ -177,5 +199,31 @@ private void RemoveZeroReferenceAssets(BuildMapContext context, List<CollectAsse
allCollectAssets.Remove(removeValue);
}
}

#region 共享资源打包规则
/// <summary>
/// 共享资源打包前置处理
/// </summary>
protected virtual void PreProcessPackShareBundle(BuildParameters buildParameters, CollectCommand command, Dictionary<string, BuildAssetInfo> allBuildAssetInfos)
{
}

/// <summary>
/// 共享资源打包后置处理
/// </summary>
protected virtual void PostProcessPackShareBundle()
{
}

/// <summary>
/// 获取共享资源包名称
/// </summary>
protected virtual PackRuleResult GetShareBundleName(BuildAssetInfo buildAssetInfo)
{
string bundleName = Path.GetDirectoryName(buildAssetInfo.AssetInfo.AssetPath);
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
return result;
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ void IBuildTask.Run(BuildContext context)
// 检测基础构建参数
buildParametersContext.CheckBuildParameters();

// 检测不被支持的参数
if (buildParameters.EnableSharePackRule)
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportSharePackRule, $"{nameof(EBuildPipeline.RawFileBuildPipeline)} not support share pack rule !");
throw new Exception(message);
}

// 检测不被支持的构建模式
if (buildParameters.BuildMode == EBuildMode.DryRunBuild)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal enum ErrorCode
PackageOutputDirectoryExists = 115,
RecommendScriptBuildPipeline = 130,
BuildPipelineNotSupportBuildMode = 140,
BuildPipelineNotSupportSharePackRule = 141,

// TaskGetBuildMap
RemoveInvalidTags = 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ private void CreateView(VisualElement parent)
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline);
var buildModeList = GetSupportBuildModes();
int defaultIndex = buildModeList.FindIndex(x => x.Equals(buildMode));
if (defaultIndex < 0)
defaultIndex = (int)(EBuildMode)buildModeList[0];
_buildModeField = new PopupField<Enum>(buildModeList, defaultIndex);
_buildModeField.label = "Build Mode";
_buildModeField.style.width = StyleWidth;
Expand All @@ -83,6 +85,8 @@ private void CreateView(VisualElement parent)
{
var encyptionClassName = AssetBundleBuilderSetting.GetPackageEncyptionClassName(PackageName, BuildPipeline);
int defaultIndex = encryptionClassTypes.FindIndex(x => x.FullName.Equals(encyptionClassName));
if (defaultIndex < 0)
defaultIndex = 0;
_encryptionField = new PopupField<Type>(encryptionClassTypes, defaultIndex);
_encryptionField.label = "Encryption";
_encryptionField.style.width = StyleWidth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected override void ExecuteBuild()
buildParameters.BuildMode = buildMode;
buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = GetPackageVersion();
buildParameters.EnableSharePackRule = true;
buildParameters.VerifyBuildingResult = true;
buildParameters.FileNameStyle = fileNameStyle;
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected override void ExecuteBuild()
buildParameters.BuildMode = buildMode;
buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = GetPackageVersion();
buildParameters.EnableSharePackRule = true;
buildParameters.VerifyBuildingResult = true;
buildParameters.FileNameStyle = fileNameStyle;
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public PackRuleResult(string bundleName, string bundleExtension)
_bundleExtension = bundleExtension;
}

/// <summary>
/// 结果是否有效
/// </summary>
public bool IsValid()
{
return string.IsNullOrEmpty(_bundleName) == false && string.IsNullOrEmpty(_bundleExtension) == false;
}

/// <summary>
/// 获取资源包全名称
/// </summary>
Expand All @@ -41,6 +49,20 @@ public string GetBundleName(string packageName, bool uniqueBundleName)
fullName = $"{bundleName}.{_bundleExtension}";
return fullName.ToLower();
}

/// <summary>
/// 获取共享资源包全名称
/// </summary>
public string GetShareBundleName(string packageName, bool uniqueBundleName)
{
string fullName;
string bundleName = EditorTools.GetRegularPath(_bundleName).Replace('/', '_').Replace('.', '_').ToLower();
if (uniqueBundleName)
fullName = $"{packageName}_share_{bundleName}.{_bundleExtension}";
else
fullName = $"share_{bundleName}.{_bundleExtension}";
return fullName.ToLower();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ReportSummary
public bool AutoCollectShaders;

// 构建参数
public bool EnableSharePackRule;
public string EncryptionClassName;
public EFileNameStyle FileNameStyle;
public ECompressOption CompressOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void FillViewData(BuildReport buildReport)
_items.Add(new ItemWrapper("Package Version", buildReport.Summary.BuildPackageVersion));

_items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("Settings", string.Empty));
_items.Add(new ItemWrapper("Collect Settings", string.Empty));
_items.Add(new ItemWrapper("Unique Bundle Name", $"{buildReport.Summary.UniqueBundleName}"));
_items.Add(new ItemWrapper("Enable Addressable", $"{buildReport.Summary.EnableAddressable}"));
_items.Add(new ItemWrapper("Location To Lower", $"{buildReport.Summary.LocationToLower}"));
Expand All @@ -77,6 +77,7 @@ public void FillViewData(BuildReport buildReport)

_items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("Build Params", string.Empty));
_items.Add(new ItemWrapper("Enable Share Pack Rule", $"{buildReport.Summary.EnableSharePackRule}"));
_items.Add(new ItemWrapper("Encryption Class Name", buildReport.Summary.EncryptionClassName));
_items.Add(new ItemWrapper("FileNameStyle", $"{buildReport.Summary.FileNameStyle}"));
_items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ namespace YooAsset
{
public static class EditorSimulateModeHelper
{
/// <summary>
/// 编辑器下模拟构建清单
/// </summary>
public static string SimulateBuild(string buildPipelineName, string packageName) { throw new System.Exception("Only support in unity editor !"); }
public static string SimulateBuild(string buildPipelineName, string packageName)
{
throw new System.Exception("Only support in unity editor !");
}

public static string SimulateBuild(EDefaultBuildPipeline buildPipeline, string packageName)
{
throw new System.Exception("Only support in unity editor !");
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ private List<BundleInfo> ConvertToDownloadList(List<PackageBundle> downloadList)
}

// 查询相关
#if UNITY_WECHAT_GAME
private WeChatWASM.WXFileSystemManager _wxFileSystemMgr;
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
if (_wxFileSystemMgr == null)
_wxFileSystemMgr = WeChatWASM.WX.GetFileSystemManager();
string filePath = WeChatWASM.WX.env.USER_DATA_PATH + packageBundle.FileName;
string result = _wxFileSystemMgr.AccessSync(filePath);
return result.Equals("access:ok");
}
#else
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return false;
}
#endif

private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
Expand Down Expand Up @@ -116,6 +133,10 @@ public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList)
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;

// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
Expand All @@ -137,6 +158,10 @@ public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[]
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList)
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;

// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
Expand Down Expand Up @@ -194,6 +219,10 @@ public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetIn
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in checkList)
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;

// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using OxGKit.LoggingSystem;
using System.Collections.Generic;
using UnityEngine;

namespace OxGFrame.NetFrame
{
Expand Down

0 comments on commit 0b6f82d

Please sign in to comment.