在Android设备上运行时从Unity文件夹脚本加载纹理表

时间:2017-03-30 13:58:47

标签: c# android unity3d texture2d

我可以从外部网址加载图片并将它们保存到我的Unity项目文件夹中,当我在我的电脑上运行它(统一播放器场景)它完美地工作时我可以将位于我项目中的图像加载到纹理表中并显示它但是在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;


    }

它在我的电脑上看起来works fine 以及它在我的手机not working

上的显示效果

1 个答案:

答案 0 :(得分:1)

目录&#34;资产\照片&#34;在编辑器中运行项目时存在,但它在Android手机上不存在。

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

Here's一个如何使用它的有用示例