StarForceBuildEventHandler.cs 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 Jiang Yin. All rights reserved.
  4. // Homepage: https://gameframework.cn/
  5. // Feedback: mailto:ellan@gameframework.cn
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using System.IO;
  9. using UnityEditor;
  10. using UnityEngine;
  11. using UnityGameFramework.Editor.ResourceTools;
  12. namespace MetaClient.Editor
  13. {
  14. public sealed class StarForceBuildEventHandler : IBuildEventHandler
  15. {
  16. public bool ContinueOnFailure
  17. {
  18. get
  19. {
  20. return false;
  21. }
  22. }
  23. public void OnPreprocessAllPlatforms(string productName, string companyName, string gameIdentifier, string gameFrameworkVersion, string unityVersion, string applicableGameVersion, int internalResourceVersion,
  24. Platform platforms, AssetBundleCompressionType assetBundleCompression, string compressionHelperTypeName, bool additionalCompressionSelected, bool forceRebuildAssetBundleSelected, string buildEventHandlerTypeName, string outputDirectory, BuildAssetBundleOptions buildAssetBundleOptions,
  25. string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, string buildReportPath)
  26. {
  27. string streamingAssetsPath = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "StreamingAssets"));
  28. string[] fileNames = Directory.GetFiles(streamingAssetsPath, "*", SearchOption.AllDirectories);
  29. foreach (string fileName in fileNames)
  30. {
  31. if (fileName.Contains(".gitkeep"))
  32. {
  33. continue;
  34. }
  35. File.Delete(fileName);
  36. }
  37. Utility.Path.RemoveEmptyDirectory(streamingAssetsPath);
  38. }
  39. public void OnPostprocessAllPlatforms(string productName, string companyName, string gameIdentifier, string gameFrameworkVersion, string unityVersion, string applicableGameVersion, int internalResourceVersion,
  40. Platform platforms, AssetBundleCompressionType assetBundleCompression, string compressionHelperTypeName, bool additionalCompressionSelected, bool forceRebuildAssetBundleSelected, string buildEventHandlerTypeName, string outputDirectory, BuildAssetBundleOptions buildAssetBundleOptions,
  41. string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, string buildReportPath)
  42. {
  43. }
  44. public void OnPreprocessPlatform(Platform platform, string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath)
  45. {
  46. }
  47. public void OnBuildAssetBundlesComplete(Platform platform, string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, AssetBundleManifest assetBundleManifest)
  48. {
  49. }
  50. public void OnOutputUpdatableVersionListData(Platform platform, string versionListPath, int versionListLength, int versionListHashCode, int versionListCompressedLength, int versionListCompressedHashCode)
  51. {
  52. }
  53. public void OnPostprocessPlatform(Platform platform, string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, bool isSuccess)
  54. {
  55. if (!outputPackageSelected)
  56. {
  57. return;
  58. }
  59. if (platform != Platform.Windows)
  60. {
  61. return;
  62. }
  63. string streamingAssetsPath = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "StreamingAssets"));
  64. string[] fileNames = Directory.GetFiles(outputPackagePath, "*", SearchOption.AllDirectories);
  65. foreach (string fileName in fileNames)
  66. {
  67. string destFileName = Utility.Path.GetRegularPath(Path.Combine(streamingAssetsPath, fileName.Substring(outputPackagePath.Length)));
  68. FileInfo destFileInfo = new FileInfo(destFileName);
  69. if (!destFileInfo.Directory.Exists)
  70. {
  71. destFileInfo.Directory.Create();
  72. }
  73. File.Copy(fileName, destFileName);
  74. }
  75. }
  76. }
  77. }