gpt4 book ai didi

android - 我如何在 Unity 的 Android 上本地测试 AssetBundle (DLC)?

转载 作者:行者123 更新时间:2023-11-29 23:19:21 24 4
gpt4 key购买 nike

我正在尝试为我目前正在开发的游戏测试一些 AssetBundle。我想使用它是因为我不想让游戏占用太多空间。我仍然不知道服务器如何工作以及如何将它们上传到那里。我正在搜索如何执行此操作,并在此处找到了一些巧妙的东西:AssetBundle (DLC) data load to Android phone at runtime [UNITY]但它讲述了一些关于上传到服务器和东西的东西,但我想在本地测试它。有什么推荐吗?

根据 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 () {

}
}

但它显示以下错误:无法打开存档文件:C:/Users/Chris/Desktop/myDLC/Assets/StreamingAssets/myassetBundle

This is the asset bundle name

最佳答案

看看AssetBundle.LoadFromFile .

这允许您从设备的本地存储加载您的 assetbundle 文件。这意味着您不必先上传/下载它们。

它看起来像下面这样:

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 或外部存储。

关于android - 我如何在 Unity 的 Android 上本地测试 AssetBundle (DLC)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54675260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com