WebGLPostBuild.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor.Callbacks;
  4. using UnityEditor;
  5. using System.IO;
  6. namespace Paroxe.PdfRenderer.Internal
  7. {
  8. public class WebGLPostBuild : ScriptableObject
  9. {
  10. private static string[] FilesToCopy = {
  11. @"Plugins/WebGL/pdf.js.bytes",
  12. @"Plugins/WebGL/pdf.js.map.bytes",
  13. @"Plugins/WebGL/pdf.worker.js.bytes",
  14. @"Plugins/WebGL/pdf.worker.js.map.bytes"
  15. };
  16. private static string[] FoldersToCopy =
  17. {
  18. @"Plugins/WebGL/cmaps"
  19. };
  20. [PostProcessBuild]
  21. public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
  22. {
  23. if (target == BuildTarget.WebGL)
  24. {
  25. ScriptableObject scriptableObject = CreateInstance<WebGLPostBuild>();
  26. MonoScript script = MonoScript.FromScriptableObject(scriptableObject);
  27. string scriptPath = AssetDatabase.GetAssetPath(script);
  28. DestroyImmediate(scriptableObject);
  29. DirectoryInfo directoryInfo = new DirectoryInfo(scriptPath);
  30. string baseFolder = directoryInfo.Parent.Parent.Parent.FullName;
  31. foreach (string sourceFile in FilesToCopy)
  32. {
  33. string sourceFileFullPath = Path.Combine(baseFolder, sourceFile);
  34. // Remove ".bytes" from filename
  35. string destFileName = new FileInfo(sourceFileFullPath).Name;
  36. destFileName = destFileName.Substring(0, destFileName.Length - 6);
  37. File.Copy(sourceFileFullPath, Path.Combine(pathToBuiltProject, destFileName), true);
  38. }
  39. foreach (string sourceFolder in FoldersToCopy)
  40. {
  41. string sourceFolderFullPath = Path.Combine(baseFolder, sourceFolder);
  42. DirectoryInfo sourceDirectory = new DirectoryInfo(sourceFolderFullPath);
  43. string targetFolder = sourceFolder.Replace(@"Plugins/WebGL/", string.Empty);
  44. targetFolder = Path.Combine(pathToBuiltProject, targetFolder);
  45. if (!Directory.Exists(targetFolder))
  46. Directory.CreateDirectory(targetFolder);
  47. foreach (FileInfo file in sourceDirectory.GetFiles())
  48. {
  49. if (file.Extension.EndsWith("meta", StringComparison.OrdinalIgnoreCase))
  50. continue;
  51. File.Copy(file.FullName, Path.Combine(targetFolder, file.Name), true);
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }