CmdBuildAssetBundle.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using XGame.Editor.Asset;
  2. using System.IO;
  3. namespace XGame.Editor.Build
  4. {
  5. [BuildCommand((uint)BuildCommandPriority.BuildAssetBundle)]
  6. class CmdBuildAssetBundle : BaseBuildCommand, ICommandExecuterAsync
  7. {
  8. public void Execute()
  9. {
  10. //sbp推荐每次打包都是全量打包
  11. var abOutputPathPath = PathDefine.AssetBundleOutputPath;
  12. if (Directory.Exists(abOutputPathPath))
  13. {
  14. //直接删除文件夹。Directory.Exists在Windows会存在文件夹大小写的问题,如果该目录下刚好存在大小写不一致的同名文件夹,会导致后续文件判断出问题,保险起见,直接删了
  15. UnityEditor.FileUtil.DeleteFileOrDirectory(abOutputPathPath);
  16. }
  17. //if (isDistributedAB)
  18. //{
  19. // UnityEditor.EditorApplication.LockReloadAssemblies();
  20. // var mainNodeTask = new MainNodeTask(Context.config, OnMainNodeCompleted);
  21. // mainNodeTask.Start();
  22. // return;
  23. //}
  24. //资源打包成AB包
  25. if (XBuildPipeline.BuildAssetBundles())
  26. {
  27. this.Completed();
  28. }
  29. else
  30. {
  31. this.Completed(BuildErrorCode.BuildAssetBundleFailed);
  32. }
  33. }
  34. //private void OnMainNodeCompleted(bool isSuccess)
  35. //{
  36. // UnityEditor.EditorApplication.UnlockReloadAssemblies();
  37. // var code = BuildErrorCode.CmdCompleted;
  38. // if (isSuccess)
  39. // {
  40. // //打包manifest
  41. // if (!KBuildPipeline.BuildManifestBundle())
  42. // {
  43. // code = BuildErrorCode.BuildAssetBundleFailed;
  44. // BuildLog.Error($"Build ManifestBundle failed.");
  45. // }
  46. // }
  47. // else if (!KBuildPipeline.BuildAssetBundles())
  48. // {
  49. // code = BuildErrorCode.BuildAssetBundleFailed;
  50. // }
  51. // this.Completed(code);
  52. //}
  53. }
  54. }