【问题标题】:Loading a table of texture from unity folder scripting while running on android device在 Android 设备上运行时从统一文件夹脚本加载纹理表
【发布时间】:2017-08-24 12:14:01
【问题描述】:

当我在我的电脑上运行它时,我可以从外部 url 加载图像并将它们保存到我的统一项目文件夹中(统一播放器场景)它完美地工作我可以将位于我的项目中的图像加载到纹理表中并显示它但它在 android 设备上运行时不起作用。它不会将图像加载到纹理中

DirectoryInfo info = new DirectoryInfo(@"Assets\Photos\");
    int nbImage;

    nbImage = info.GetFiles("*.jpg").Length;
    Debug.Log(nbImage);
    Textures = new Texture2D[nbImage];
    for (int i = 0; i < nbImage; i++)
    {
        string e = Application.streamingAssetsPath + "/" + i + ".jpg";
        byte[] bytes;
        bytes = System.IO.File.ReadAllBytes(e);
        load_s01_texture = new Texture2D(1, 1);
        load_s01_texture.LoadImage(bytes);
        Textures[i] = load_s01_texture as Texture2D;


    }

这是它在我的电脑上的样子 这就是我手机上的样子

【问题讨论】:

  • 你试过调试吗?如果没有,您可以通过在手机上启用 USB 调试(在开发人员设置中)并使用 ADB(一个常用命令是 adb logcat -s Unity)来实现。
  • 是的,我尝试在 android studio 上调试它,我认为这是路径问题。他找不到我保存在项目中的图像的路径

标签: c# android unity3d texture2d


【解决方案1】:

在编辑器中运行项目时“Assets\Photos”目录存在,但在Android手机上不存在。

如果你想在运行时加载图片或其他资源,你必须使用resources文件夹。

Here's一个有用的例子说明如何使用它

【讨论】:

  • 我想补充一下,你也可以在 Android 上使用StreamingAssets
  • 它不会在我的手机上显示图像,但它可以在我的电脑上正常工作。我正在使用“Textures = Resources.LoadAll("Textures", typeof(Texture2D));”获取图片
  • 我之前没有看到你的回复。您正在将“纹理”传递给 LoadAll 方法,但在您的问题中您提到该文件夹​​名为“照片”,所以我认为错误在那里
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-01
  • 1970-01-01
  • 2021-11-25
  • 1970-01-01
  • 1970-01-01
  • 2019-06-09
  • 1970-01-01
相关资源
最近更新 更多