KinectCopyPluginDataHelper.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. public static class KinectCopyPluginDataHelper
  7. {
  8. private const string DataDirSuffix = "_Data";
  9. private const string PluginsDirName = "Plugins";
  10. private static Dictionary<BuildTarget, string> TargetToDirName = new Dictionary<BuildTarget, string>()
  11. {
  12. {BuildTarget.StandaloneWindows, "x86"},
  13. {BuildTarget.StandaloneWindows64, "x86_64"}
  14. };
  15. public static void CopyPluginData(BuildTarget target, string buildTargetPath, string subDirToCopy)
  16. {
  17. string subDirName;
  18. if (!TargetToDirName.TryGetValue (target, out subDirName))
  19. {
  20. // No work to do
  21. return;
  22. }
  23. // Get Required Paths
  24. var buildName = Path.GetFileNameWithoutExtension(buildTargetPath);
  25. var targetDir = Directory.GetParent(buildTargetPath);
  26. var separator = Path.DirectorySeparatorChar;
  27. var buildDataDir = targetDir.FullName + separator + buildName + DataDirSuffix + separator;
  28. var tgtPluginsDir = buildDataDir + separator + PluginsDirName + separator + subDirToCopy + separator;
  29. var srcPluginsDir = Application.dataPath + separator + PluginsDirName + separator + subDirName + separator + subDirToCopy + separator;
  30. CopyAll (new DirectoryInfo (srcPluginsDir), new DirectoryInfo(tgtPluginsDir));
  31. }
  32. /// <summary>
  33. /// Recursive Copy Directory Method
  34. /// </summary>
  35. private static void CopyAll(DirectoryInfo source, DirectoryInfo target)
  36. {
  37. // Check if the source directory exists, if not, don't do any work.
  38. if (!Directory.Exists(source.FullName))
  39. {
  40. return;
  41. }
  42. // Check if the target directory exists, if not, create it.
  43. if (!Directory.Exists(target.FullName))
  44. {
  45. Directory.CreateDirectory(target.FullName);
  46. }
  47. // Copy each file into it’s new directory.
  48. foreach (var fileInfo in source.GetFiles())
  49. {
  50. fileInfo.CopyTo (Path.Combine (target.ToString (), fileInfo.Name), true);
  51. }
  52. // Copy each subdirectory using recursion.
  53. foreach (var subDirInfo in source.GetDirectories())
  54. {
  55. DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(subDirInfo.Name);
  56. CopyAll(subDirInfo, nextTargetSubDir);
  57. }
  58. }
  59. }