在Unity3D中从iPhone加载图像



我使用iOS Unity插件将图像路径发送到Unity。在团结中,我尝试使用接收的路径来获得此图像(我没有其他想法将图像从iPhone发送到Unity)。问题:我仍然无法获得图像。 www错误:在此服务器上找不到请求的URL。

//Tried both "file:///..." and "file://..."
string path = "file://var/mobile/Applications/173DE26D-4C0E-4DF7-9DC6-9CBB7D4FC954/Documents/Images/image.png" 
Texture texture;
IEnumerator WaitForRequest(WWW www) {
    yield return www;
    if (www.error == null) {
        texture = www.texture;
    }    
}
void Start() {
    WWW www = new WWW(path);
    StartCoroutine(WaitForRequest(www));
}

确保使用

的文件。
System.IO.File.Exists("/var/mobile/Applications/173DE26D-4C0E-4DF7-9DC6-9CBB7D4FC954/Documents/Images/image.png") 

因为您的代码看起来正确。

另外,您应该使用application.persistentdatapath。

而不是硬编码路径。
string path = "file://" + System.IO.Path.Combine(Application.persistentDataPath, "Images/image.png");

顺便说一句,我认为绝对文件URL应该始终以file:///开头。

最新更新