- Home /
Is it possible to exclude StreamingAssets depending on target platform?
For standalone builds, MovieTextures work great, but on many other platforms, movies must be placed in StreamingAssets for use with platform-specific movie playing APIs. To avoid including the movie files when building for standalone, is it possible to exclude the StreamingAssets folder?
Workarounds, such as a post-build hook that deletes the StreamingAssets folder from the standalone build, are also welcome.
Answer by zach-r-d · Jul 31, 2015 at 11:10 PM
For anyone who comes across this, here is the script I ended up writing to delete the StreamingAssets folder from a standalone build:
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.Collections;
using System.IO;
public static class DeleteBuildStreamingAssetsIfUnnecessary {
[PostProcessBuild(100)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
string streamingAssetsPath = null;
switch (target) {
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64:
case BuildTarget.StandaloneLinux:
case BuildTarget.StandaloneLinux64:
case BuildTarget.StandaloneLinuxUniversal:
{
// windows and linux use "_Data" folder
string root = Path.Combine(Path.GetDirectoryName(pathToBuiltProject),Path.GetFileNameWithoutExtension(pathToBuiltProject)+"_Data");
streamingAssetsPath = Path.Combine(root,"StreamingAssets");
}
break;
case BuildTarget.StandaloneOSXIntel:
case BuildTarget.StandaloneOSXIntel64:
case BuildTarget.StandaloneOSXUniversal:
{
streamingAssetsPath = Path.Combine(pathToBuiltProject, "Contents");
streamingAssetsPath = Path.Combine(streamingAssetsPath, "Resources");
streamingAssetsPath = Path.Combine(streamingAssetsPath, "Data");
streamingAssetsPath = Path.Combine(streamingAssetsPath, "StreamingAssets");
}
break;
}
if (streamingAssetsPath == null || !Directory.Exists(streamingAssetsPath))
return;
Directory.Delete(streamingAssetsPath, true);
}
}
Your answer
Follow this Question
Related Questions
Build addressables in custom build script 4 Answers
How can I utilize different source files when building to different platforms? 0 Answers
How to execute script in scene on build before static batch? 2 Answers
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
How to build from script while using build settings from editor? 0 Answers