Commit 8da46df5 authored by mercury233's avatar mercury233

update pic.LoadImage

parent 587fe386
Pipeline #23956 failed with stages
in 3 minutes and 28 seconds
...@@ -734,10 +734,10 @@ public static class UIHelper ...@@ -734,10 +734,10 @@ public static class UIHelper
} }
public static Texture2D GetTexture2D(string path) public static Texture2D GetTexture2D(string path)
{ {
if (!File.Exists(path)) if (!File.Exists(path))
{ {
return null; return null;
} }
var pic = new Texture2D(0, 0); var pic = new Texture2D(0, 0);
pic.LoadImage(File.ReadAllBytes(path)); pic.LoadImage(File.ReadAllBytes(path));
...@@ -747,13 +747,7 @@ public static class UIHelper ...@@ -747,13 +747,7 @@ public static class UIHelper
public static async Task<Texture2D> GetTexture2DAsync(string path) public static async Task<Texture2D> GetTexture2DAsync(string path)
{ {
var pic = new Texture2D(0, 0); var pic = new Texture2D(0, 0);
// Unity < 2021.2 pic.LoadImage(await File.ReadAllBytesAsync(path));
var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true);
var data = new byte[stream.Length];
await stream.ReadAsync(data, 0, (int) stream.Length);
pic.LoadImage(data);
// Unity >= 2021.2
// pic.LoadImage(await File.ReadAllBytesAsync(path));
return pic; return pic;
} }
...@@ -764,6 +758,7 @@ public static class UIHelper ...@@ -764,6 +758,7 @@ public static class UIHelper
ZipEntry entry = zip[file]; ZipEntry entry = zip[file];
entry.Extract(stream); entry.Extract(stream);
//await Task.Run(() => { entry.Extract(stream); }); //await Task.Run(() => { entry.Extract(stream); });
//并不能这样写,这个zip库好像不支持多线程
pic.LoadImage(stream.ToArray()); pic.LoadImage(stream.ToArray());
return pic; return pic;
} }
......
...@@ -13,3 +13,4 @@ MonoBehaviour: ...@@ -13,3 +13,4 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
assetDefaultFramerate: 60 assetDefaultFramerate: 60
m_DefaultFrameRate: 60
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment