6

我正在使用unity5.3.3,我想知道如何从资产包中获取资产,其名称相同但保存在不同的文件夹中。我的 AssetBundle 文件夹按以下方式设置:

 MyAssets -> this Folder is packed as an AssetBundle
  -ThemeOne(folder)
     - Logo.png
  -ThemerTwo(folder)
     - Logo.Png

当我这样做的时候AssetBundle.LoadAssetAsync("Logo")。我最终在第一个(ThemeOne)文件夹中获得徽标。那么如何访问另一个文件夹中的文件呢?

我刚刚创建了一个示例项目,以便您查看。检查文件夹 Assets\AssetBundleSample\SampleAssets\Theme 和脚本 LoadAssets

4

5 回答 5

0

似乎是一个错误。Unity 5.3.3 版中仍然存在。

请参阅:http ://answers.unity3d.com/questions/1083400/asset-bundle-cant-have-multiple-files-with-the-sam.html

于 2016-08-22T14:15:47.343 回答
0

您可以将 ThemeOne(folder) 和 ThemeTwo(folder) 放在资源文件夹中 assets 下,然后使用类似这样的东西

(AudioClip)(Resources.Load ("Sounds/" + "myaudioclip", typeof(AudioClip)) as AudioClip)

同样,首先加载您的 png 给文件夹名称,因为我给出了声音,然后加载文件名称,因为我给出了 myaudioclip 。投射为纹理或你想要的东西

于 2016-05-10T05:45:38.013 回答
0

我不太确定这是否可能,您应该阅读Explicit Naming of assets,它在 Unity 5.6 上已过时,仅供参考。这允许您明确命名您包含在捆绑包中的资产。或者,您可以尝试,

bundle.LoadAsset("/Assets/ThemerTwo/Logo.png")

但一般来说,在同一个包中拥有相同命名的资产是一种不好的做法。

于 2017-06-15T06:01:04.930 回答
0

作为统一官方文档提供

public string BundleURL;
   public string AssetName;
   IEnumerator Start() {
     // Download the file from the URL. It will not be saved in the Cache
     using (WWW www = new WWW(BundleURL)) {
         yield return www;
         if (www.error != null)
             throw new Exception("WWW download had an error:" + www.error);
         AssetBundle bundle = www.assetBundle;
         if (AssetName == "")
             Instantiate(bundle.mainAsset);
         else
             Instantiate(bundle.LoadAsset(AssetName));
                   // Unload the AssetBundles compressed contents to conserve memory
                   bundle.Unload(false);

     } // memory is freed from the web stream (www.Dispose() gets called implicitly)
   }

BundleURL 将使用您的实际资产所在的路径。您还可以将Application.dataPath与您指定的路径字符串结合使用。

于 2016-05-10T07:29:08.573 回答
-1

您可以使用方法 LoadAssetAtPath() 来指定完整路径,而不仅仅是资产名称。

例子:

LoadAssetAtPath("Assets/Texture/Logo.jpg", typeof(Texture2D));

此处的文档:http: //docs.unity3d.com/ScriptReference/AssetDatabase.LoadAssetAtPath.html

于 2016-05-10T05:45:07.323 回答