【问题标题】:Loading image from iphone in Unity3d在 Unity3d 中从 iphone 加载图像
【发布时间】:2012-10-20 23:07:57
【问题描述】:

我使用 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));
}

【问题讨论】:

  • 您只是想访问本地文件以加载纹理,还是稍后将其放在网络中?
  • 我只想访问本地文件以加载纹理。

标签: c# .net ios unity3d


【解决方案1】:

使用

确保文件存在
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:/// 开头。

【讨论】:

  • 为了简化代码示例,我对路径进行了硬编码 - 在项目中它是动态的。问题出在错误的道路上-我的错)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-04
  • 1970-01-01
  • 2011-11-15
相关资源
最近更新 更多