Browse Source

ResourcesComponent异步加载中加载ab用了一个同步方法,改为异步方法

tanghai 7 years ago
parent
commit
f30a03de8b

+ 2 - 2
Unity/Assets/Scripts/Module/AssetsBundle/AssetsBundleLoaderAsync.cs

@@ -39,10 +39,10 @@ namespace ETModel
 			base.Dispose();
 			base.Dispose();
 		}
 		}
 
 
-		public Task<AssetBundle> LoadAsync(string bundleName)
+		public Task<AssetBundle> LoadAsync(string path)
 		{
 		{
 			this.tcs = new TaskCompletionSource<AssetBundle>();
 			this.tcs = new TaskCompletionSource<AssetBundle>();
-			this.request = AssetBundle.LoadFromFileAsync(Path.Combine(PathHelper.AppHotfixResPath, bundleName));
+			this.request = AssetBundle.LoadFromFileAsync(path);
 			return this.tcs.Task;
 			return this.tcs.Task;
 		}
 		}
 	}
 	}

+ 7 - 8
Unity/Assets/Scripts/Module/AssetsBundle/ResourcesComponent.cs

@@ -1,7 +1,6 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.IO;
 using System.IO;
-using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using UnityEngine;
 using UnityEngine;
@@ -48,7 +47,7 @@ namespace ETModel
 
 
 			base.Dispose();
 			base.Dispose();
 
 
-			//Log.Debug($"destroy assetbundle: {this.Name}");
+			//Log.Debug($"desdroy assetbundle: {this.Name}");
 
 
 			this.AssetBundle?.Unload(true);
 			this.AssetBundle?.Unload(true);
 		}
 		}
@@ -250,7 +249,7 @@ namespace ETModel
 			assetBundleName = assetBundleName.ToLower();
 			assetBundleName = assetBundleName.ToLower();
 			string[] dependencies = ResourcesHelper.GetSortedDependencies(assetBundleName);
 			string[] dependencies = ResourcesHelper.GetSortedDependencies(assetBundleName);
 
 
-			//Log.Debug($"-----------dep load {assetBundleName} dep: {dependencies.ToList().ListToString()}");
+			// Log.Debug($"-----------dep load {assetBundleName} dep: {dependencies.ToList().ListToString()}");
 			foreach (string dependency in dependencies)
 			foreach (string dependency in dependencies)
 			{
 			{
 				if (string.IsNullOrEmpty(dependency))
 				if (string.IsNullOrEmpty(dependency))
@@ -302,14 +301,14 @@ namespace ETModel
 
 
 			string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
 			string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
 			AssetBundle assetBundle = null;
 			AssetBundle assetBundle = null;
-			if (File.Exists(p))
+			if (!File.Exists(p))
 			{
 			{
-				assetBundle = AssetBundle.LoadFromFile(p);
+				p = Path.Combine(PathHelper.AppResPath, assetBundleName);
 			}
 			}
-			else
+			
+			using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = ComponentFactory.Create<AssetsBundleLoaderAsync>())
 			{
 			{
-				p = Path.Combine(PathHelper.AppResPath, assetBundleName);
-				assetBundle = AssetBundle.LoadFromFile(p);
+				assetBundle = await assetsBundleLoaderAsync.LoadAsync(p);
 			}
 			}
 
 
 			if (assetBundle == null)
 			if (assetBundle == null)