我如何在 Unity 的 Android 上本地测试 AssetBundle (DLC)?
How I can test AssetBundle (DLC) locally on Android in Unity?
我正在尝试为我目前正在开发的游戏测试一些 AssetBundle。我想使用它是因为我不想让游戏占用很多 space。我仍然不知道服务器如何工作以及如何将它们上传到那里。我正在搜索如何执行此操作,并在此处找到了一些巧妙的东西:
但它讲述了一些关于上传到服务器和东西的东西,但我想在本地测试它。有什么推荐吗?
根据 Remy 告诉我的内容,我的代码如下所示:
public class LoadFromFileExample : MonoBehaviour {
// Use this for initialization
void Start () {
string fileName = "planes";
var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, fileName));
if (myLoadedAssetBundle == null)
{
Debug.Log("Failed to load AssetBundle!");
return;
}
var prefab = myLoadedAssetBundle.LoadAsset< GameObject > ("andy");
Instantiate(prefab);
myLoadedAssetBundle.Unload(false);
}
// Update is called once per frame
void Update () {
}
}
但是显示如下错误:Unable to open archive file: C:/Users/Chris/Desktop/myDLC/Assets/StreamingAssets/myassetBundle
This is the asset bundle name
这允许您从设备的本地存储加载您的 assetbundle 文件。这意味着您不必先 upload/download 它们。
它将如下所示:
string fileName = "fooAssetBundle";//name of the assetbundle you want to load
var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, fileName));//Creates a filepath starting at the streamingAssetsPath and appends filename to it.
var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("MyObject");//Create a GameObject from the assetbundle
Instantiate(prefab);//instantiate the GameObject
myLoadedAssetBundle.Unload(false);//Unload the assetbundle from memory as it isn't used anymore
上面的示例使用 Application.StreamingAssetsPath
但这可以是您想要的任何路径,例如 Application.PersistentDataPath
或外部存储。
我正在尝试为我目前正在开发的游戏测试一些 AssetBundle。我想使用它是因为我不想让游戏占用很多 space。我仍然不知道服务器如何工作以及如何将它们上传到那里。我正在搜索如何执行此操作,并在此处找到了一些巧妙的东西:
根据 Remy 告诉我的内容,我的代码如下所示:
public class LoadFromFileExample : MonoBehaviour {
// Use this for initialization
void Start () {
string fileName = "planes";
var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, fileName));
if (myLoadedAssetBundle == null)
{
Debug.Log("Failed to load AssetBundle!");
return;
}
var prefab = myLoadedAssetBundle.LoadAsset< GameObject > ("andy");
Instantiate(prefab);
myLoadedAssetBundle.Unload(false);
}
// Update is called once per frame
void Update () {
}
}
但是显示如下错误:Unable to open archive file: C:/Users/Chris/Desktop/myDLC/Assets/StreamingAssets/myassetBundle
This is the asset bundle name
这允许您从设备的本地存储加载您的 assetbundle 文件。这意味着您不必先 upload/download 它们。
它将如下所示:
string fileName = "fooAssetBundle";//name of the assetbundle you want to load
var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, fileName));//Creates a filepath starting at the streamingAssetsPath and appends filename to it.
var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("MyObject");//Create a GameObject from the assetbundle
Instantiate(prefab);//instantiate the GameObject
myLoadedAssetBundle.Unload(false);//Unload the assetbundle from memory as it isn't used anymore
上面的示例使用 Application.StreamingAssetsPath
但这可以是您想要的任何路径,例如 Application.PersistentDataPath
或外部存储。