对不起,我对统一和c#非常陌生。
我试着读一幅图像,并把它作为一种纹理。
当我在计算机上使用图像时,代码会工作,但是,当我用android设备(电话和AR眼镜)尝试它时,我无法正确地指定文件路径。如何正确地指定android设备的文件路径,或者是否有方法可以获得这些文件路径?
谢谢你提前提供帮助!:)
void Start()
{
thisTexture = new Texture2D(100, 100);
//string path = "C:/Users/kenny/Desktop/5th March/im.png"; //this works
string path = "file:///storage/emulated/0/im2.png"; // this doesnt work
bytes = File.ReadAllBytes(path);
thisTexture.LoadImage(bytes);
GetComponent<Renderer>().material.mainTexture = thisTexture;
}发布于 2020-04-10 19:12:57
对于移动设备来说,从普通路径获取文件并不那么简单。
这样做的一种方法是使用资源文件夹。在根文件夹(资产)中,创建一个名为Resources的新文件夹。把你的照片放在那里。
然后你可以做这样的事情:
// path without file extension!
var texture = Resources.Load<Texture2D>("path/to/texture");您可以在这里获得有关此功能的更多引用:https://forum.unity.com/threads/how-to-load-a-image-from-the-resources-folder-to-a-texture2d.101542/
或者,您可以使用StreamingAssets文件夹,但这是另一个故事。
https://stackoverflow.com/questions/61138054
复制相似问题