从 iPhone 中在 Unity3d 中加载图像

3

我使用iOS Unity插件将图像路径发送到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));
}

你是想要访问本地文件以加载纹理,还是该文件后续会在网络上? - Kay
我只想访问本地文件以加载纹理。 - JastinBall
1个回答

3

请确保文件已经存在,使用以下命令:

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:///开头。

1
为了代码示例的简单,我将路径硬编码 - 在实际项目中它是动态的。问题在于错误的路径 - 是我的错) - JastinBall

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接