我目前正在使用Unity和Eclipse开发android库。
我设法获取了" content://com.android.providers...."或获得" / document / image:123"。
但是,我不确定将什么放入WWW的参数中。 当我使用
WWW(" / document / image:123");
我将找不到文件异常。
使用时
WWW(" file:// content://com.android.providers....");
我会得到"打开图像错误:内容// com.android.providers .....不是绝对路径。
有人可以指导我如何工作吗?
答案 0 :(得分:2)
file://
和content://
都是协议 - 您必须使用其中之一。 Unity建议使用file://
。 http://docs.unity3d.com/ScriptReference/WWW.html
您是否也可以访问文件(应用程序可以阅读)?这对我有用:WWW www = new WWW("file://" + Application.persistentDataPath + "/my-file.txt");
答案 1 :(得分:1)
使用WWW类时,应使用 file:// 协议在 Application.persistentDataPath 中加载本地文件。另请注意,在 Windows 和 Windows应用商店上使用文件协议访问本地文件时,您必须指定 file:/// (使用三个斜杠):http://docs.unity3d.com/ScriptReference/WWW.html
您可以使用System.Url类将本地路径转换为URL,它应该适用于所有平台。
public static string GetFileURL(string path)
{
return (new System.Uri(path)).AbsoluteUri;
}
答案 2 :(得分:-1)
您是否偶然尝试在StreamingAssets
文件夹中打开文件?如果是这样,您将需要使用WWW
类从jar文件中提取它。你想要的路径是:
string path = "jar:file://" + Application.dataPath + "!/assets/";