I’ve built a menuitem script to generate streamed level assetbundles from the currently open scene (script below). It worked once but now I get “Error building Player: Failed to move streamed scene file to ‘/Assets/New Resource.unity3d’.” whenever I try to build a bundle. How do I resolve this? Unity crashed at one stage while I was testing this script - is that related?
I’m on unity 4 pro.
Garrett
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
public class ExportLevelAssetBundles
{
[MenuItem("Assets/Build Level AssetBundle from Open Level")]
static void ExportResource ()
{
//bring up save panel to get path and file name
string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
//if there is a path
if (path.Length != 0)
{
//for testing, show the chosen path
//Debug.Log(path);
//get the current application pathway and split it into an array by forward slashes
string[] s = Application.dataPath.Split('/');
//the project name is two forward slashes back from the end of the array
string projectName = s[s.Length - 2];
//Debug.Log("project = " + projectName);
//get the position of the project name in the path chosen in savefilepanel
int offset = path.IndexOf(projectName);
//if offset does not return -1 (i.e. no position)
if (offset != -1)
{
//add the length of the project name to the offset
offset = offset + projectName.Length;
//slice the path into a shortened relative path with the filename
string shortenedpath = path.Substring(offset, path.Length - offset);
Debug.Log(shortenedpath);
//use an ampty levels array to build the currently open scene
string[] levels = new string[] {};
//build a streamed scene at the choosen location
BuildPipeline.BuildPlayer (levels, shortenedpath, BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);
}
else
{
//if no offset the user is trying to export outside the current project path
Debug.Log("You must export to a location in the current projects path.");
}
}
}
}