| | |
| | | |
| | | public static class YooAssetBuildTool |
| | | { |
| | | private static Action s_PendingDllBuildAction; |
| | | private static string s_PendingDllBuildSource; |
| | | |
| | | private static string[] GetAllPackageNames() |
| | | { |
| | | var setting = AssetBundleCollectorSettingData.Setting; |
| | |
| | | /// </summary> |
| | | public static bool BuildAllPackagesCore(bool incremental, string streamingAssetsOutputPath = null) |
| | | { |
| | | // 打包前生成 UI -> 图集预加载映射,保证运行时预加载策略与最新资源一致。 |
| | | TryBuildUIAtlasPreloadMap("YooAssetBuildTool.BuildAllPackagesCore"); |
| | | |
| | | CollectResBeforeUpdate.SyncCollectors(); |
| | | |
| | | // ---- 打包前:HybridCLR DLL(增量模式跳过)---- |
| | |
| | | |
| | | AssetDatabase.Refresh(); |
| | | return success; |
| | | } |
| | | |
| | | private static bool TryBuildUIAtlasPreloadMap(string source) |
| | | { |
| | | try |
| | | { |
| | | const string builderTypeName = "UIAtlasPreloadMapBuilder"; |
| | | const string buildMethodName = "Build"; |
| | | |
| | | var builderType = Type.GetType(builderTypeName); |
| | | if (builderType == null) |
| | | { |
| | | var assemblies = AppDomain.CurrentDomain.GetAssemblies(); |
| | | for (int i = 0; i < assemblies.Length; i++) |
| | | { |
| | | builderType = assemblies[i].GetType(builderTypeName, throwOnError: false, ignoreCase: false); |
| | | if (builderType != null) |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (builderType == null) |
| | | { |
| | | Debug.LogWarning($"[YooAssetBuildTool] 未找到 {builderTypeName},跳过预加载映射生成。source={source}"); |
| | | return false; |
| | | } |
| | | |
| | | var buildMethod = builderType.GetMethod(buildMethodName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); |
| | | if (buildMethod == null) |
| | | { |
| | | Debug.LogWarning($"[YooAssetBuildTool] 未找到 {builderTypeName}.{buildMethodName},跳过预加载映射生成。source={source}"); |
| | | return false; |
| | | } |
| | | |
| | | buildMethod.Invoke(null, null); |
| | | Debug.Log($"[YooAssetBuildTool] 预加载映射已生成。source={source}"); |
| | | return true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Debug.LogWarning($"[YooAssetBuildTool] 预加载映射生成失败(继续打包)。source={source}, error={ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | public static bool CopyStreamingAssetsToOutputPath(string outputPath) |
| | |
| | | return; |
| | | } |
| | | |
| | | TryBuildUIAtlasPreloadMap("YooAssetBuildTool.BuildDllAndPlayer"); |
| | | if (!EnsureEditorReadyForDllBuild("YooAssetBuildTool.BuildDllAndPlayer", BuildDllAndPlayerCore)) |
| | | return; |
| | | |
| | | BuildDllAndPlayerCore(); |
| | | } |
| | | |
| | | private static void BuildDllAndPlayerCore() |
| | | { |
| | | string outputPath = GetPlayerOutputPath(); |
| | | |
| | | // Step 1: 拷贝 DLL 并打包 Dll Package |
| | | EditorUtility.DisplayProgressBar("YooAsset 打包中...", "正在拷贝 HybridCLR DLL...", 0.1f); |
| | | if (!CopyHybridCLRDlls()) |
| | |
| | | [MenuItem("YooAsset工具/打包单个Package/Dll (HybridCLR)", false, 316)] |
| | | private static void BuildDll() |
| | | { |
| | | string version = GenerateVersion(); |
| | | string versionPreview = DateTime.Now.ToString("yyyy-MM-dd-HHmm"); |
| | | if (!EditorUtility.DisplayDialog("确认打包", |
| | | $"打包 Package: Dll (HybridCLR)\n版本: {version}\n平台: {EditorUserBuildSettings.activeBuildTarget}\n\n将先拷贝 HybridCLR 生成的 DLL 到 {HYBRIDCLR_DLLS_ASSETS_PATH}", |
| | | $"打包 Package: Dll (HybridCLR)\n版本(预计): {versionPreview}\n平台: {EditorUserBuildSettings.activeBuildTarget}\n\n将先拷贝 HybridCLR 生成的 DLL 到 {HYBRIDCLR_DLLS_ASSETS_PATH}", |
| | | "开始", "取消")) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | TryBuildUIAtlasPreloadMap("YooAssetBuildTool.BuildDll"); |
| | | if (!EnsureEditorReadyForDllBuild("YooAssetBuildTool.BuildDll", BuildDllCore)) |
| | | return; |
| | | |
| | | BuildDllCore(); |
| | | } |
| | | |
| | | private static void BuildDllCore() |
| | | { |
| | | string version = GenerateVersion(); |
| | | |
| | | EditorUtility.DisplayProgressBar("YooAsset 打包中...", "正在拷贝 HybridCLR DLL...", 0.2f); |
| | | if (!CopyHybridCLRDlls()) |
| | |
| | | AssetDatabase.Refresh(); |
| | | } |
| | | |
| | | private static bool EnsureEditorReadyForDllBuild(string source, Action pendingAction) |
| | | { |
| | | // 代码生成后可能触发脚本重编译,DLL 打包必须在编译结束后执行。 |
| | | if (EditorApplication.isCompiling || EditorApplication.isUpdating) |
| | | { |
| | | s_PendingDllBuildAction = pendingAction; |
| | | s_PendingDllBuildSource = source; |
| | | EditorApplication.update -= TryRunPendingDllBuildWhenEditorReady; |
| | | EditorApplication.update += TryRunPendingDllBuildWhenEditorReady; |
| | | |
| | | Debug.LogWarning($"[YooAssetBuildTool] 编辑器正在编译或刷新,DLL 打包已加入自动队列。source={source}"); |
| | | EditorUtility.DisplayDialog( |
| | | "已加入自动队列", |
| | | "检测到脚本正在编译或资源正在刷新。\n\n编译完成后将自动继续执行 DLL 打包,无需手动再次点击。", |
| | | "确定"); |
| | | return false; |
| | | } |
| | | |
| | | if (BuildPipeline.isBuildingPlayer) |
| | | { |
| | | Debug.LogWarning($"[YooAssetBuildTool] 当前正在构建 Player,跳过 DLL 打包。source={source}"); |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private static void TryRunPendingDllBuildWhenEditorReady() |
| | | { |
| | | if (s_PendingDllBuildAction == null) |
| | | { |
| | | EditorApplication.update -= TryRunPendingDllBuildWhenEditorReady; |
| | | return; |
| | | } |
| | | |
| | | if (EditorApplication.isCompiling || EditorApplication.isUpdating || BuildPipeline.isBuildingPlayer) |
| | | return; |
| | | |
| | | var action = s_PendingDllBuildAction; |
| | | var source = s_PendingDllBuildSource; |
| | | s_PendingDllBuildAction = null; |
| | | s_PendingDllBuildSource = null; |
| | | EditorApplication.update -= TryRunPendingDllBuildWhenEditorReady; |
| | | |
| | | try |
| | | { |
| | | Debug.Log($"[YooAssetBuildTool] 编译已结束,自动继续执行 DLL 打包。source={source}"); |
| | | action?.Invoke(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Debug.LogError($"[YooAssetBuildTool] 自动执行 DLL 打包失败。source={source}, error={ex}"); |
| | | EditorUtility.DisplayDialog("自动打包失败", "编译结束后自动执行 DLL 打包失败,请查看 Console 日志。", "确定"); |
| | | } |
| | | } |
| | | |
| | | private static void BuildSingleWithDialog(string packageName) |
| | | { |
| | | string version = GenerateVersion(); |