浏览代码

replace www with UnityWebRequest

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
5c101f4c
共有 2 个文件被更改,包括 29 次插入20 次删除
  1. 26
      com.unity.uiwidgets/Runtime/engine2/AndroidPlatformUtil.cs
  2. 23
      com.unity.uiwidgets/Runtime/painting/image_provider.cs

26
com.unity.uiwidgets/Runtime/engine2/AndroidPlatformUtil.cs


using System;
using System.IO;
using System.Runtime.InteropServices;
using UnityEngine.Networking;
using NativeBindings = Unity.UIWidgets.ui.NativeBindings;
namespace Unity.UIWidgets.engine2 {
public static class AndroidPlatformUtil {

internal static string unpackFile(string file) {
var dir = Application.temporaryCachePath + "/";
if (!File.Exists(dir + file)) {
WWW unpackerWWW = new WWW("jar:file://" + Application.dataPath + "!/assets/" + file);
while (!unpackerWWW.isDone) {
} // This will block in the webplayer.
var path = "jar:file://" + Application.dataPath + "!/assets/" + file;
using(var unpackerWWW = UnityWebRequest.Get(path)) {
unpackerWWW.SendWebRequest();
while (!unpackerWWW.isDone) {
} // This will block in the webplayer.
if (unpackerWWW.isNetworkError || unpackerWWW.isHttpError) {
Debug.Log($"Failed to get file \"{path}\": {unpackerWWW.error}");
return "";
}
var data = unpackerWWW.downloadHandler.data;
FileInfo fileInfo = new System.IO.FileInfo(dir + file);
fileInfo.Directory.Create();
File.WriteAllBytes(fileInfo.FullName, data);
if (!string.IsNullOrEmpty(unpackerWWW.error)) {
Debug.Log("Error unpacking 'jar:file://" + Application.dataPath + "!/assets/" + file +
"'");
dir = "";
return dir + file;
throw new Exception("not loaded");
System.IO.FileInfo fileInfo = new System.IO.FileInfo(dir + file);
fileInfo.Directory.Create();
System.IO.File.WriteAllBytes(fileInfo.FullName, unpackerWWW.bytes);
}
return dir + file;

23
com.unity.uiwidgets/Runtime/painting/image_provider.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.engine2;

#else
var path = "file://" + Path.Combine(Application.streamingAssetsPath, key.file);
#endif
WWW unpackerWWW = new WWW(path);
while (!unpackerWWW.isDone) {
} // This will block in the webplayer.
if (unpackerWWW.bytes.Length > 0) {
return decode(unpackerWWW.bytes);
}
using(var unpackerWWW = UnityWebRequest.Get(path)) {
unpackerWWW.SendWebRequest();
while (!unpackerWWW.isDone) {
} // This will block in the webplayer.
if (unpackerWWW.isNetworkError || unpackerWWW.isHttpError) {
throw new Exception($"Failed to get file \"{path}\": {unpackerWWW.error}");
}
throw new Exception("not loaded");
var data = unpackerWWW.downloadHandler.data;
if (data.Length > 0) {
return decode(data);
}
throw new Exception("not loaded");
}
}
IEnumerator _loadBytes(FileImage key) {

正在加载...
取消
保存