我正在尝试构建一个统一项目,在我的项目中,我必须使用统一webview在app中显示网页,方法是在本地加载或通过一次存储该网页的缓存。我已经尝试通过下载网页本地加载,但没有互联网加载的html文件的内容,但CSS,JS和图像不是。在本地加载我已经将文件夹和HTML文件粘贴到项目中的文件夹 - > Assests->流媒体资产。文件夹和HTML文件的图像为Streaming Assets directory Image,使用带下划线的文件夹和文件。在统一编辑器中,文件的链接提供如下: - Unity Editor Image和用于加载文件的脚本在下面
case RuntimePlatform.OSXEditor:
case RuntimePlatform.OSXPlayer:
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.Android:
if (Url.StartsWith("http")) {
webViewObject.LoadURL(Url.Replace(" ", "%20"));
} else {
webViewObject.LoadURL("StreamingAssets/" + Url.Replace(" ", "%20"));
var src = System.IO.Path.Combine(Application.streamingAssetsPath, Url);
var dst = System.IO.Path.Combine(Application.persistentDataPath, Url);
var result = "";
if (src.Contains("://")) {
var www = new WWW(src);
yield return www;
result = www.text;
} else {
result = System.IO.File.ReadAllText(src);
}
System.IO.File.WriteAllText(dst, result);
webViewObject.LoadURL("file://" + dst.Replace(" ", "%20"));
}
if (Application.platform != RuntimePlatform.Android) {
webViewObject.EvaluateJS(
"window.addEventListener('load', function() {" +
" window.Unity = {" +
" call:function(msg) {" +
" var iframe = document.createElement('IFRAME');" +
" iframe.setAttribute('src', 'unity:' + msg);" +
" document.documentElement.appendChild(iframe);" +
" iframe.parentNode.removeChild(iframe);" +
" iframe = null;" +
" }" +
" }" +
"}, false);");
}
break;
#else
如果有人知道请帮助。