How do I build Scene Asset Bundles?
I have trouble building Asset bundles that contain scenes. I have previously successfully build a scene into an asset bundle by tagging it, like any other object, in the inspector, and then running BuildAssetBundles, letting it do everything automatically. However, I want to be able to add scenes programmatically to a bundle, how do I do that? The code I use builds only one bundle and produces NO errors. Can someone help me, please? Here is my Exporter code:
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;
class Bundler:Editor {
[MenuItem("ProjectMagenta/BuildAssetBundles")]
static void BuildAssetBundles() {
AssetBundleBuild[] assetBundleBuild = new AssetBundleBuild[2];
string scenesFilename = "TemporaryPlatformFileName";
string assetsFilename = "TemporaryAssetFileName";
assetBundleBuild[0].assetBundleName = scenesFilename;
assetBundleBuild[1].assetBundleName = assetsFilename;
List<string> validAssetNames = new List<string>();
List<string> validSceneAssetNames = new List<string>();
string[] scenePaths = Directory.GetFiles(Application.dataPath, "*.unity", SearchOption.AllDirectories);
for(int i = 0; i < scenePaths.Length; i++) {
scenePaths[i] = scenePaths[i].Replace(@"\", "/");
}
Later in same class, after filling up validSceneAssetNames and validAssetNames:
assetBundleBuild[0].assetNames = validSceneAssetNames.ToArray();
assetBundleBuild[1].assetNames = validAssetNames.ToArray();
BuildPipeline.BuildAssetBundles(Application.dataPath, assetBundleBuild, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows64);
}
}
Your answer
Follow this Question
Related Questions
Assigning Asset Bundle in Script 2 Answers
Asset Bundle dependcies when including scenes 1 Answer
Buy Unity Assets 0 Answers
How to check if scene exists in SceneManager? 2 Answers
Loading many sprites at runtime 0 Answers