在Unity3d中从iPhone加载图像 [英] Loading image from iphone in Unity3d

查看:62
本文介绍了在Unity3d中从iPhone加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用iOS Unity插件将图像路径发送到unity.在Unity中,我尝试使用接收的路径获取此图像(我不知道如何将图像从iphone发送到unity).问题:我仍然无法获得图像. WWW错误:在此服务器上找不到请求的URL.

I send image path to unity using iOS Unity plugin. And in Unity I try to get this image using received path (I have no other idea how to send image from iphone to unity). The problem: I still can't get the image. WWW Error: The requested URL was not found on this server.

//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") 

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

because your code looks correct.

此外,您应该使用Application.persistentDataPath.而不是对路径进行硬编码.

Also, instead of hardcoding the path you should use Application.persistentDataPath.

string path = "file://" + System.IO.Path.Combine(Application.persistentDataPath, "Images/image.png");

顺便说一句,我认为绝对文件网址应始终以file:///开头.

BTW, I think an absolute file url should always start with file:///.

这篇关于在Unity3d中从iPhone加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆