Skip to content

Commit 2b0b978

Browse files
author
wanderer
committed
修复异步加载读取同一个文件的问题
1 parent 588f5b1 commit 2b0b978

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

GameFramework/Editor/AssetBundleEditor/AssetBundleBuildEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class AssetBundleBuildEditor : EditorWindow
2929
//压缩内容
3030
string[] _compressionOptionsContent = new string[] { "No Compression", "Standard Compression (LZMA)", "Chunk Based Compression (LZ4)" };
3131

32-
[MenuItem("Tools/Asset Bundle/AssetBundle Build Options %#O")]
32+
[MenuItem("Tools/Asset Bundle/AssetBundle Build Options #&O")]
3333
public static void AssetBundilesOptions()
3434
{
3535
_rootPath = Path.GetDirectoryName(Path.GetFullPath(Application.dataPath));

GameFramework/Editor/AssetBundleEditor/AssetBundleEditor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public bool _haspopupFoldersWindow
5151
[MenuItem("Tools/Asset Bundle/Asset Bundle Editor")]
5252
private static void MainWindow()
5353
{
54-
GetWindowWithRect<AssetBundleEditor>(new Rect(100, 100, 1200, 600), false, "Asset Bundle Editor");
54+
//GetWindowWithRect<AssetBundleEditor>(new Rect(100, 100, 1200, 600), false, "Asset Bundle Editor");
55+
GetWindow<AssetBundleEditor>("Asset Bundle Editor");
5556
}
5657

5758

GameFramework/Runtime/Resource/BundleAssetsHelper.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,17 +429,28 @@ private IEnumerator LoadAssetBundleFromPathAsync(string path, Action<AssetBundle
429429

430430
using (Stream abStream = _isEncrypt ? new EncryptFileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, 1024 * 4, false) : new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None, 1024 * 4, false))
431431
{
432-
float loadTime = Time.realtimeSinceStartup;
433-
var ablfsa = AssetBundle.LoadFromStreamAsync(abStream);
434-
while (!ablfsa.isDone)
432+
while (!abStream.CanRead)
435433
{
436-
progress?.Invoke(ablfsa.progress);
437434
yield return null;
438435
}
436+
string fileName = Path.GetFileNameWithoutExtension(path);
439437
yield return null;
440-
loadTime = Time.realtimeSinceStartup - loadTime;
441-
Debug.Log($"LoadAssetBundleFromPath Async time spent: {loadTime} {path} ");
442-
callback?.Invoke(ablfsa.assetBundle);
438+
AssetBundle assetBundle;
439+
if (!_liveAssetBundle.TryGetValue(fileName, out assetBundle))
440+
{
441+
float loadTime = Time.realtimeSinceStartup;
442+
var ablfsa = AssetBundle.LoadFromStreamAsync(abStream);
443+
while (!ablfsa.isDone)
444+
{
445+
progress?.Invoke(ablfsa.progress);
446+
yield return null;
447+
}
448+
yield return null;
449+
loadTime = Time.realtimeSinceStartup - loadTime;
450+
Debug.Log($"LoadAssetBundleFromPath Async time spent: {loadTime} {path} ");
451+
assetBundle = ablfsa.assetBundle;
452+
}
453+
callback?.Invoke(assetBundle);
443454
}
444455
}
445456
#endregion

0 commit comments

Comments
 (0)