public static Dictionary <string, UnityEngine.Object> LoadBundle(string assetBundleName) { assetBundleName = assetBundleName.ToLower(); Dictionary <string, UnityEngine.Object> objects = new Dictionary <string, UnityEngine.Object>(); if (!Define.IsAsync) { if (Define.IsEditor) { string[] realPath = null; realPath = Define.GetAssetPathsFromAssetBundle(assetBundleName); foreach (string s in realPath) { //string assetName = Path.GetFileNameWithoutExtension(s); UnityEngine.Object resource = Define.LoadAssetAtPath(s); objects.Add(resource.name, resource); } } return(objects); } string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName); UnityEngine.AssetBundle assetBundle = null; if (File.Exists(p)) { assetBundle = UnityEngine.AssetBundle.LoadFromFile(p); } else { p = Path.Combine(PathHelper.AppResPath, assetBundleName); assetBundle = UnityEngine.AssetBundle.LoadFromFile(p); } if (assetBundle == null) { // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功 UnityEngine.Debug.LogWarning($"assets bundle not found: {assetBundleName}"); return(objects); } UnityEngine.Object[] assets = assetBundle.LoadAllAssets(); foreach (UnityEngine.Object asset in assets) { objects.Add(asset.name, asset); } return(objects); }
private static string[] GetDependencies(this ResourcesComponent self, string assetBundleName) { string[] dependencies = Array.Empty <string>(); if (self.DependenciesCache.TryGetValue(assetBundleName, out dependencies)) { return(dependencies); } if (!Define.IsAsync) { if (Define.IsEditor) { dependencies = Define.GetAssetBundleDependencies(assetBundleName, true); } } else { dependencies = self.AssetBundleManifestObject.GetAllDependencies(assetBundleName); } self.DependenciesCache.Add(assetBundleName, dependencies); return(dependencies); }
private string[] GetDependencies(string assetBundleName) { string[] dependencies = Array.Empty <string>(); if (DependenciesCache.TryGetValue(assetBundleName, out dependencies)) { return(dependencies); } if (!Define.IsAsync) { if (Define.IsEditor) { dependencies = Define.GetAssetBundleDependencies(assetBundleName, true); } } else { dependencies = this.AssetBundleManifestObject.GetAllDependencies(assetBundleName); } DependenciesCache.Add(assetBundleName, dependencies); return(dependencies); }
private static async ETTask <ABInfo> LoadOneBundleAsync(this ResourcesComponent self, string assetBundleName) { assetBundleName = assetBundleName.BundleNameToLower(); ABInfo abInfo; if (self.bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); return(null); } string p = ""; AssetBundle assetBundle = null; if (!Define.IsAsync) { if (Define.IsEditor) { string[] realPath = Define.GetAssetPathsFromAssetBundle(assetBundleName); foreach (string s in realPath) { string assetName = Path.GetFileNameWithoutExtension(s); UnityEngine.Object resource = Define.LoadAssetAtPath(s); self.AddResource(assetBundleName, assetName, resource); } if (realPath.Length > 0) { abInfo = self.AddChild <ABInfo, string, AssetBundle>(assetBundleName, null); self.bundles[assetBundleName] = abInfo; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); } else { Log.Error("Bundle not exist! BundleName: " + assetBundleName); } // 编辑器模式也不能同步加载 await TimerComponent.Instance.WaitAsync(100); return(abInfo); } } p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName); if (!File.Exists(p)) { p = Path.Combine(PathHelper.AppResPath, assetBundleName); } Log.Debug("Async load bundle BundleName : " + p); // if (!File.Exists(p)) // { // Log.Error("Async load bundle not exist! BundleName : " + p); // return null; // } assetBundle = await AssetBundleHelper.UnityLoadBundleAsync(p); if (assetBundle == null) { // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功 Log.Warning($"assets bundle not found: {assetBundleName}"); return(null); } abInfo = self.AddChild <ABInfo, string, AssetBundle>(assetBundleName, assetBundle); self.bundles[assetBundleName] = abInfo; return(abInfo); //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); }
private static void LoadOneBundle(this ResourcesComponent self, string assetBundleName) { assetBundleName = assetBundleName.BundleNameToLower(); ABInfo abInfo; if (self.bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); return; } if (!Define.IsAsync) { if (Define.IsEditor) { string[] realPath = null; realPath = Define.GetAssetPathsFromAssetBundle(assetBundleName); foreach (string s in realPath) { string assetName = Path.GetFileNameWithoutExtension(s); UnityEngine.Object resource = Define.LoadAssetAtPath(s); self.AddResource(assetBundleName, assetName, resource); } if (realPath.Length > 0) { abInfo = self.AddChild <ABInfo, string, AssetBundle>(assetBundleName, null); self.bundles[assetBundleName] = abInfo; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); } else { Log.Error($"assets bundle not found: {assetBundleName}"); } } return; } string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName); AssetBundle assetBundle = null; if (File.Exists(p)) { assetBundle = AssetBundle.LoadFromFile(p); } else { p = Path.Combine(PathHelper.AppResPath, assetBundleName); assetBundle = AssetBundle.LoadFromFile(p); } if (assetBundle == null) { // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功 Log.Warning($"assets bundle not found: {assetBundleName}"); return; } if (!assetBundle.isStreamedSceneAssetBundle) { // 异步load资源到内存cache住 var assets = assetBundle.LoadAllAssets(); foreach (UnityEngine.Object asset in assets) { self.AddResource(assetBundleName, asset.name, asset); } } abInfo = self.AddChild <ABInfo, string, AssetBundle>(assetBundleName, assetBundle); self.bundles[assetBundleName] = abInfo; //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}"); }