|
| 1 | +using System.IO; |
| 2 | +using UnityEditor; |
| 3 | +using UnityEditor.Callbacks; |
| 4 | +using UnityEngine; |
| 5 | + |
| 6 | +// copies empty StreamingAssets/ folders into build, as they are not automatically included |
| 7 | + |
| 8 | +namespace UnityLibrary |
| 9 | +{ |
| 10 | + public class PostBuildCopyEmptyFolders : MonoBehaviour |
| 11 | + { |
| 12 | + [PostProcessBuildAttribute(1)] |
| 13 | + public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) |
| 14 | + { |
| 15 | + Debug.Log("<color=#00FF00>### POSTBUILD : COPY EMPTY STREAMINGASSETS-FOLDERS ###</color>"); |
| 16 | + Debug.Log("Build done: " + pathToBuiltProject); |
| 17 | + |
| 18 | + // get output root |
| 19 | + var root = Path.GetDirectoryName(pathToBuiltProject); |
| 20 | + var appName = Path.GetFileNameWithoutExtension(pathToBuiltProject); |
| 21 | + |
| 22 | + // copy empty streaming asset folders to build |
| 23 | + var sourcePath = Application.streamingAssetsPath; |
| 24 | + var targetPath = Path.Combine(root, appName + "_Data", "StreamingAssets"); |
| 25 | + //Debug.Log("sourcePath= "+ sourcePath); |
| 26 | + //Debug.Log("targetPath= " + targetPath); |
| 27 | + CopyFolderStructure(sourcePath, targetPath); |
| 28 | + } |
| 29 | + |
| 30 | + // recursive folder copier |
| 31 | + static public void CopyFolderStructure(string sourceFolder, string destFolder) |
| 32 | + { |
| 33 | + if (Directory.Exists(destFolder)) |
| 34 | + { |
| 35 | + |
| 36 | + } |
| 37 | + else |
| 38 | + { |
| 39 | + Directory.CreateDirectory(destFolder); |
| 40 | + } |
| 41 | + |
| 42 | + string[] folders = Directory.GetDirectories(sourceFolder); |
| 43 | + foreach (string folder in folders) |
| 44 | + { |
| 45 | + string name = Path.GetFileName(folder); |
| 46 | + string dest = Path.Combine(destFolder, name); |
| 47 | + CopyFolderStructure(folder, dest); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments