3 日前、私はunity 4.x のアセット バンドルを使い続けています。これまでに試したことを以下に示します。
このコード スニペットを使用してシーン アセット バンドルを作成すると、.unity3d シーン アセット バンドルが正常に作成されます
public class SceneAssetBundleMaker : EditorWindow {
bool groupEnabled;
public static string sceneName;
static string sceneNameWithPath;
static string sceneNameWithPathAssetBundel;
[MenuItem("AB Scene/BuildSceneAsset")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(SceneAssetBundleMaker));
}
void OnInspectorUpdate()
{
Repaint();
}
void OnGUI()
{
EditorGUILayout.BeginVertical("Box");
GUILayout.Label("Enter Scene Name");
sceneName = EditorGUILayout.TextField(sceneName);
if (GUILayout.Button("Make Asset Bundle"))
{
if (sceneName != null)
myBuild();
else
Debug.LogError("sceneName must be entered");
}
EditorGUILayout.EndVertical();
}
static void myBuild()
{
// string[] levels = { "Assets/Scene/SimpleBakingPlanAndBoxes.unity" };
//string[] levels = { "Assets/Scene/"+ sceneName+ ".unity" };
sceneNameWithPath = "Assets/_project/_scenes/" + sceneName + ".unity";
Debug.Log("sceneNameWithPath" + sceneNameWithPath);
string[] levels = { sceneNameWithPath };
Debug.Log("levels : " + levels.Length);
Debug.Log("levels 0 : " + levels[0]);
sceneNameWithPathAssetBundel = "Assets/AssetBundles/" +sceneName + ".unity3d";
string v = BuildPipeline.BuildStreamedSceneAssetBundle(levels, sceneNameWithPathAssetBundel, BuildTarget.StandaloneWindows);
Debug.Log(v);
//"Streamed-Level1.unity3d"
//BuildPipeline.BuildStreamedSceneAssetBundle(levels, "Streamed-Level1.unity3d", BuildTarget.StandaloneWindows64);
}
}
このコードがシーン アセット バンドルのダウンロードに使用されている間
public IEnumerator LoadSceneBundle(string assetBundleSceneName, string orignialName) {
url = "file://" + Application.dataPath + "/AssetBundles/" + assetBundleSceneName + ".unity3d";
Debug.Log("scene load url : " + url);
using (WWW www = WWW.LoadFromCacheOrDownload(url,1)){
yield return www;
if (www.error != null) {
throw new Exception("WWW donwload had an error : " + url + " " + www.error);
//Debug.Log("");
}
AssetBundle ab = www.assetBundle;
Debug.Log("Main Asset :: " + www.assetBundle.mainAsset);
ab.LoadAll();
Application.LoadLevel(orignialName);
ab.Unload(false);
}
}
私が切り替えている2 つのシーンは、両方ともこのコードによるアセット バンドルからのものです。コードは正常に動作しますが、常にではありません。ビルド スタンドアロンで同じ状況に直面しているときに、シーンが読み込まれる場合と読み込まれない場合があります。
展開後、AssetsBundel のフォルダーを作成し、そこに私の assetbudel シーン ファイルを配置しましたが、すべて無駄です。