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