Optimized the speed of simulate build.

优化了编辑器下模拟构建的速度。
pull/9/head
hevinci 2022-05-05 21:12:44 +08:00
parent c3c18cd555
commit c196cd84d3
17 changed files with 85 additions and 72 deletions

View File

@ -30,8 +30,8 @@ namespace YooAsset.Editor
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
if (parameters.BuildMode == EBuildMode.DryRunBuild)
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}";
else if(parameters.BuildMode == EBuildMode.FastRunBuild)
PipelineOutputDirectory += $"_{EBuildMode.FastRunBuild}";
else if(parameters.BuildMode == EBuildMode.SimulateBuild)
PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}";
}
/// <summary>
@ -53,7 +53,7 @@ namespace YooAsset.Editor
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
if (Parameters.BuildMode == EBuildMode.FastRunBuild)
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
{
throw new Exception("Should never get here !");
}
@ -132,7 +132,7 @@ namespace YooAsset.Editor
new TaskCopyBuildinFiles(), //拷贝内置文件
};
if (buildParameters.BuildMode == EBuildMode.FastRunBuild)
if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
BuildRunner.EnableLog = false;
else
BuildRunner.EnableLog = true;

View File

@ -1,22 +1,21 @@
using System;
using UnityEditor;
using UnityEditor;
namespace YooAsset.Editor
{
public static class AssetBundleRuntimeBuilder
public static class AssetBundleSimulateBuilder
{
private static string _manifestFilePath = string.Empty;
/// <summary>
/// 快速模式构建
/// 模拟构建
/// </summary>
public static void FastBuild()
public static void SimulateBuild()
{
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
BuildParameters buildParameters = new BuildParameters();
buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.FastRunBuild;
buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion;
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
@ -26,7 +25,7 @@ namespace YooAsset.Editor
if (buildResult)
{
string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildTarget);
_manifestFilePath = $"{pipelineOutputDirectory}_{EBuildMode.FastRunBuild}/{YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildVersion)}";
_manifestFilePath = $"{pipelineOutputDirectory}_{EBuildMode.SimulateBuild}/{YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildVersion)}";
}
else
{
@ -35,9 +34,9 @@ namespace YooAsset.Editor
}
/// <summary>
/// 获取构建的补丁清单文件路径
/// 获取构建的补丁清单路径
/// </summary>
public static string GetPatchManifestFilePath()
public static string GetPatchManifestPath()
{
return _manifestFilePath;
}

View File

@ -10,7 +10,7 @@ namespace YooAsset.Editor
/// <summary>
/// 执行资源构建上下文
/// </summary>
public static BuildMapContext CreateBuildMap()
public static BuildMapContext CreateBuildMap(EBuildMode buildMode)
{
BuildMapContext context = new BuildMapContext();
Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>(1000);
@ -19,7 +19,7 @@ namespace YooAsset.Editor
AssetBundleCollectorSettingData.Setting.CheckConfigError();
// 2. 获取所有主动收集的资源
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets();
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode);
// 3. 剔除未被引用的依赖资源
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();

View File

@ -21,9 +21,9 @@ namespace YooAsset.Editor
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
// 快速构建模式下跳过引擎构建
// 模拟构建模式下跳过引擎构建
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.FastRunBuild)
if (buildMode == EBuildMode.SimulateBuild)
return;
BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions();

View File

@ -12,7 +12,8 @@ namespace YooAsset.Editor
{
void IBuildTask.Run(BuildContext context)
{
var buildMapContext = BuildMapCreater.CreateBuildMap();
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode);
context.SetContextObject(buildMapContext);
BuildRunner.Log("构建内容准备完毕!");

View File

@ -15,8 +15,8 @@ namespace YooAsset.Editor
{
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
// 快速构建模式下跳过验证
if (buildParametersContext.Parameters.BuildMode == EBuildMode.FastRunBuild)
// 模拟构建模式下跳过验证
if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
return;
// 验证构建结果

View File

@ -16,14 +16,14 @@ namespace YooAsset.Editor
/// </summary>
IncrementalBuild,
/// <summary>
/// 快速构建模式
/// </summary>
FastRunBuild,
/// <summary>
/// 演练构建模式
/// </summary>
DryRunBuild,
/// <summary>
/// 模拟构建模式
/// </summary>
SimulateBuild,
}
}

View File

@ -235,6 +235,10 @@ namespace YooAsset.Editor
}
private List<string> GetAllDependencies(string mainAssetPath)
{
// 注意:模拟构建模式下不需要收集依赖资源
if(AssetBundleCollectorSetting.BuildMode == EBuildMode.SimulateBuild)
return new List<string>();
List<string> result = new List<string>();
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
foreach (string assetPath in depends)

View File

@ -8,6 +8,8 @@ namespace YooAsset.Editor
{
public class AssetBundleCollectorSetting : ScriptableObject
{
public static EBuildMode BuildMode;
/// <summary>
/// 是否启用可寻址资源定位
/// </summary>
@ -43,8 +45,10 @@ namespace YooAsset.Editor
/// <summary>
/// 获取打包收集的资源文件
/// </summary>
public List<CollectAssetInfo> GetAllCollectAssets()
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
{
BuildMode = buildMode;
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
// 收集打包资源

View File

@ -98,7 +98,7 @@ namespace YooAsset.Editor
List<string> allAssets = new List<string>(1000);
// 获取所有打包的资源
List<CollectAssetInfo> allCollectInfos = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets();
List<CollectAssetInfo> allCollectInfos = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(EBuildMode.DryRunBuild);
List<string> collectAssets = allCollectInfos.Select(t => t.AssetPath).ToList();
foreach (var assetPath in collectAssets)
{

View File

@ -13,9 +13,9 @@ namespace YooAsset
}
/// <summary>
/// 编辑器下模拟运行的初始化操作
/// 编辑器下模拟模式的初始化操作
/// </summary>
internal sealed class EditorPlayModeInitializationOperation : InitializationOperation
internal sealed class EditorSimulateModeInitializationOperation : InitializationOperation
{
private enum ESteps
{
@ -24,10 +24,10 @@ namespace YooAsset
Done,
}
private readonly EditorPlayModeImpl _impl;
private readonly EditorSimulateModeImpl _impl;
private ESteps _steps = ESteps.None;
internal EditorPlayModeInitializationOperation(EditorPlayModeImpl impl)
internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl)
{
_impl = impl;
}
@ -39,7 +39,7 @@ namespace YooAsset
{
if (_steps == ESteps.Builder)
{
string manifestFilePath = EditorPlayModeHelper.DryRunBuild();
string manifestFilePath = EditorSimulateModeHelper.SimulateBuild();
if (string.IsNullOrEmpty(manifestFilePath))
{
_steps = ESteps.Done;
@ -65,7 +65,7 @@ namespace YooAsset
}
/// <summary>
/// 离线模式的初始化操作
/// 离线运行模式的初始化操作
/// </summary>
internal sealed class OfflinePlayModeInitializationOperation : InitializationOperation
{
@ -116,7 +116,7 @@ namespace YooAsset
}
/// <summary>
/// 网络模式的初始化操作
/// 网络运行模式的初始化操作
/// </summary>
internal sealed class HostPlayModeInitializationOperation : InitializationOperation
{

View File

@ -3,19 +3,19 @@ using System.Reflection;
namespace YooAsset
{
internal static class EditorPlayModeHelper
internal static class EditorSimulateModeHelper
{
private static System.Type _classType;
public static string DryRunBuild()
public static string SimulateBuild()
{
_classType = Assembly.Load("YooAsset.Editor").GetType("YooAsset.Editor.AssetBundleRuntimeBuilder");
InvokePublicStaticMethod(_classType, "FastBuild");
_classType = Assembly.Load("YooAsset.Editor").GetType("YooAsset.Editor.AssetBundleSimulateBuilder");
InvokePublicStaticMethod(_classType, "SimulateBuild");
return GetPatchManifestFilePath();
}
private static string GetPatchManifestFilePath()
{
return (string)InvokePublicStaticMethod(_classType, "GetPatchManifestFilePath");
return (string)InvokePublicStaticMethod(_classType, "GetPatchManifestPath");
}
private static object InvokePublicStaticMethod(System.Type type, string method, params object[] parameters)
{
@ -30,8 +30,8 @@ namespace YooAsset
}
}
#else
internal static class EditorPlayModeHelper
internal static class EditorSimulateModeHelper
{
public static string DryRunBuild() { throw new System.Exception("Only support in unity editor !"); }
public static string SimulateBuild() { throw new System.Exception("Only support in unity editor !"); }
}
#endif

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace YooAsset
{
internal class EditorPlayModeImpl : IBundleServices
internal class EditorSimulateModeImpl : IBundleServices
{
internal PatchManifest AppPatchManifest;
@ -13,7 +13,7 @@ namespace YooAsset
/// </summary>
public InitializationOperation InitializeAsync()
{
var operation = new EditorPlayModeInitializationOperation(this);
var operation = new EditorSimulateModeInitializationOperation(this);
OperationSystem.ProcessOperaiton(operation);
return operation;
}

View File

@ -14,17 +14,18 @@ namespace YooAsset
public enum EPlayMode
{
/// <summary>
/// 编辑器下模拟运行模式
/// 编辑器下的模拟模式
/// 注意:在初始化的时候自动构建真机运行环境。
/// </summary>
EditorPlayMode,
EditorSimulateMode,
/// <summary>
/// 离线模式
/// 离线运行模式
/// </summary>
OfflinePlayMode,
/// <summary>
/// 网络模式
/// 网络运行模式
/// </summary>
HostPlayMode,
}
@ -56,21 +57,21 @@ namespace YooAsset
}
/// <summary>
/// 编辑器下模拟运行模式参数
/// 编辑器下模拟运行模式的初始化参数
/// </summary>
public class EditorPlayModeParameters : CreateParameters
public class EditorSimulateModeParameters : CreateParameters
{
}
/// <summary>
/// 离线模式参数
/// 离线运行模式的初始化参数
/// </summary>
public class OfflinePlayModeParameters : CreateParameters
{
}
/// <summary>
/// 网络模式参数
/// 网络运行模式的初始化参数
/// </summary>
public class HostPlayModeParameters : CreateParameters
{
@ -102,7 +103,7 @@ namespace YooAsset
private static EPlayMode _playMode;
private static IBundleServices _bundleServices;
private static ILocationServices _locationServices;
private static EditorPlayModeImpl _editorPlayModeImpl;
private static EditorSimulateModeImpl _editorSimulateModeImpl;
private static OfflinePlayModeImpl _offlinePlayModeImpl;
private static HostPlayModeImpl _hostPlayModeImpl;
@ -151,8 +152,8 @@ namespace YooAsset
}
// 运行模式
if (parameters is EditorPlayModeParameters)
_playMode = EPlayMode.EditorPlayMode;
if (parameters is EditorSimulateModeParameters)
_playMode = EPlayMode.EditorSimulateMode;
else if (parameters is OfflinePlayModeParameters)
_playMode = EPlayMode.OfflinePlayMode;
else if (parameters is HostPlayModeParameters)
@ -176,12 +177,12 @@ namespace YooAsset
// 初始化资源系统
InitializationOperation initializeOperation;
if (_playMode == EPlayMode.EditorPlayMode)
if (_playMode == EPlayMode.EditorSimulateMode)
{
_editorPlayModeImpl = new EditorPlayModeImpl();
_bundleServices = _editorPlayModeImpl;
_editorSimulateModeImpl = new EditorSimulateModeImpl();
_bundleServices = _editorSimulateModeImpl;
AssetSystem.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
initializeOperation = _editorPlayModeImpl.InitializeAsync();
initializeOperation = _editorSimulateModeImpl.InitializeAsync();
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
@ -223,7 +224,7 @@ namespace YooAsset
public static UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout = 60)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorPlayMode)
if (_playMode == EPlayMode.EditorSimulateMode)
{
var operation = new EditorPlayModeUpdateStaticVersionOperation();
OperationSystem.ProcessOperaiton(operation);
@ -255,7 +256,7 @@ namespace YooAsset
public static UpdateManifestOperation UpdateManifestAsync(int resourceVersion, int timeout = 60)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorPlayMode)
if (_playMode == EPlayMode.EditorSimulateMode)
{
var operation = new EditorPlayModeUpdateManifestOperation();
OperationSystem.ProcessOperaiton(operation);
@ -285,11 +286,11 @@ namespace YooAsset
public static int GetResourceVersion()
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorPlayMode)
if (_playMode == EPlayMode.EditorSimulateMode)
{
if (_editorPlayModeImpl == null)
if (_editorSimulateModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _editorPlayModeImpl.GetResourceVersion();
return _editorSimulateModeImpl.GetResourceVersion();
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
@ -574,7 +575,7 @@ namespace YooAsset
string bundleName = _bundleServices.GetBundleName(assetPath);
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(bundleName);
if (_playMode == EPlayMode.EditorPlayMode)
if (_playMode == EPlayMode.EditorSimulateMode)
{
RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath);
OperationSystem.ProcessOperaiton(operation);
@ -635,7 +636,7 @@ namespace YooAsset
public static PatchDownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode)
if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);
@ -661,7 +662,7 @@ namespace YooAsset
public static PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode)
if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);
@ -689,7 +690,7 @@ namespace YooAsset
public static PatchDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode)
if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);
@ -723,7 +724,7 @@ namespace YooAsset
public static PatchDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorPlayMode || _playMode == EPlayMode.OfflinePlayMode)
if (_playMode == EPlayMode.EditorSimulateMode || _playMode == EPlayMode.OfflinePlayMode)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new PatchDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain);
@ -770,7 +771,7 @@ namespace YooAsset
public static PatchUnpackerOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorPlayMode)
if (_playMode == EPlayMode.EditorSimulateMode)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain);
@ -804,7 +805,7 @@ namespace YooAsset
public static UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout = 60)
{
DebugCheckInitialize();
if (_playMode == EPlayMode.EditorPlayMode)
if (_playMode == EPlayMode.EditorSimulateMode)
{
var operation = new EditorPlayModeUpdatePackageOperation();
OperationSystem.ProcessOperaiton(operation);
@ -876,7 +877,11 @@ namespace YooAsset
// 轮询更新资源系统
AssetSystem.Update();
}
internal static string MappingToAssetPath(string location)
/// <summary>
/// 资源定位地址转换为资源完整路径
/// </summary>
public static string MappingToAssetPath(string location)
{
DebugCheckLocation(location);
return _bundleServices.MappingToAssetPath(location);