-
Notifications
You must be signed in to change notification settings - Fork 469
Expand file tree
/
Copy pathPostBuildCopyEmptyFolders.cs
More file actions
54 lines (46 loc) · 1.84 KB
/
Copy pathPostBuildCopyEmptyFolders.cs
File metadata and controls
54 lines (46 loc) · 1.84 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
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
// copies empty StreamingAssets/ folders into build, as they are not automatically included
namespace UnityLibrary
{
public class PostBuildCopyEmptyFolders : MonoBehaviour
{
[PostProcessBuildAttribute(1)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
{
// only for windows
if (target != BuildTarget.StandaloneWindows) return;
Debug.Log("<color=#00FF00>### POSTBUILD : COPY EMPTY STREAMINGASSETS-FOLDERS ###</color>");
Debug.Log("Build done: " + pathToBuiltProject);
// get output root
var root = Path.GetDirectoryName(pathToBuiltProject);
var appName = Path.GetFileNameWithoutExtension(pathToBuiltProject);
// copy empty streaming asset folders to build
var sourcePath = Application.streamingAssetsPath;
var targetPath = Path.Combine(root, appName + "_Data", "StreamingAssets");
//Debug.Log("sourcePath= "+ sourcePath);
//Debug.Log("targetPath= " + targetPath);
CopyFolderStructure(sourcePath, targetPath);
}
// recursive folder copier
static public void CopyFolderStructure(string sourceFolder, string destFolder)
{
if (Directory.Exists(destFolder))
{
}
else
{
Directory.CreateDirectory(destFolder);
}
string[] folders = Directory.GetDirectories(sourceFolder);
foreach (string folder in folders)
{
string name = Path.GetFileName(folder);
string dest = Path.Combine(destFolder, name);
CopyFolderStructure(folder, dest);
}
}
}
}

