在C#Mono中以编程方式访问Unity sharedassets.assets文件中的项目

我正在研究《城市:天际线》模组,我想以编程方式访问游戏在Data文件夹中的sharedassets.assets文件,以获取网格物体/预制件。

我找到了一个名为Unity Assets Bundle Extractor(UABE)的工具,它能够打开这些文件并提取网格。

是否可以像UABE一样使用C#代码以编程方式从共享资产中提取网格?

我看过Unity文档,但到目前为止只看过此页面(不确定是否相关):https://docs.unity3d.com/ScriptReference/AssetBundle.LoadFromFile.html

我尝试从那里修改代码,但到目前为止我还没有成功,只是没有发现错误消息

var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.dataPath,"sharedassets11"));

有没有办法做到这一点?谢谢

gsephiroth 回答:在C#Mono中以编程方式访问Unity sharedassets.assets文件中的项目

查看AssetBundle.LoadFromFile的API。

您将需要第二种方法AssetBundle.LoadAsset(或者也许还有AssetBundle.LoadAllAssets):

var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.dataPath,"sharedassets11"));
if (myLoadedAssetBundle == null)
{
    Debug.Log("Failed to load AssetBundle!");
    return;
}

var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("NameOfTheAccordingObject");
Instantiate(prefab);

myLoadedAssetBundle.Unload(false);
本文链接:https://www.f2er.com/3168224.html

大家都在问