diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs index 448b602..6d21ec2 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs @@ -26,6 +26,17 @@ namespace YooAsset.Editor if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory)) throw new Exception("输出目录不能为空"); + // 检测当前是否正在构建资源包 + if (BuildPipeline.isBuildingPlayer) + throw new Exception("当前正在构建资源包,请结束后再试"); + + // 检测是否有未保存场景 + if (EditorTools.HasDirtyScenes()) + throw new Exception("检测到未保存的场景文件"); + + // 保存改动的资源 + AssetDatabase.SaveAssets(); + // 增量更新时候的必要检测 var buildMode = buildParameters.Parameters.BuildMode; if (buildMode == EBuildMode.IncrementalBuild) diff --git a/Assets/YooAsset/Editor/EditorTools.cs b/Assets/YooAsset/Editor/EditorTools.cs index 784f825..fc1effd 100644 --- a/Assets/YooAsset/Editor/EditorTools.cs +++ b/Assets/YooAsset/Editor/EditorTools.cs @@ -7,6 +7,7 @@ using System.IO; using System.Text; using UnityEngine; using UnityEditor; +using UnityEditor.SceneManagement; namespace YooAsset.Editor { @@ -265,6 +266,20 @@ namespace YooAsset.Editor } #endregion + #region SceneUtility + public static bool HasDirtyScenes() + { + var sceneCount = EditorSceneManager.sceneCount; + for (var i = 0; i < sceneCount; ++i) + { + var scene = EditorSceneManager.GetSceneAt(i); + if (scene.isDirty) + return true; + } + return false; + } + #endregion + #region 文件 /// /// 创建文件所在的目录