public virtual IEnumerator PreloadAsync() { if (_PreloadReady) { for (int i = 0; i < DepBundles.Count; ++i) { var bi = DepBundles[i]; if (bi == null || bi.Bundle == null) { _PreloadReady = false; break; } } if (_PreloadReady) { yield break; } } List <AssetBundleInfo> bundles = new List <AssetBundleInfo>(); try { var opmod = ManiItem.Manifest.MFlag; var mod = opmod; if (ManiItem.Manifest.InMain) { mod = ""; } string bundle = ManiItem.BRef; if (string.IsNullOrEmpty(bundle)) { bundle = FormatBundleName(); } var cabi = LoadAssetBundleEx(mod, bundle, true); if (cabi != null) { cabi.AddRef(); bundles.Add(cabi); while (AsyncWorkTimer.Check()) { yield return(null); } if (_PreloadReady) { yield break; } AssetBundleManifest umani; if (UnityManifests.TryGetValue(mod, out umani) && umani) { var deps = umani.GetAllDependencies(bundle); if (deps != null) { for (int i = 0; i < deps.Length; ++i) { var dep = deps[i]; var bi = LoadAssetBundleEx(mod, dep, false); if (bi != null) { bi.AddRef(); bundles.Insert(bundles.Count - 1, bi); while (AsyncWorkTimer.Check()) { yield return(null); } if (_PreloadReady) { yield break; } } } } } for (int i = 0; i < DepBundles.Count; ++i) { var bi = DepBundles[i]; if (bi != null) { bi.Release(); } } DepBundles.Clear(); DepBundles.AddRange(bundles); bundles.Clear(); _PreloadReady = true; } } finally { if (bundles != null) { for (int i = 0; i < bundles.Count; ++i) { bundles[i].Release(); } } } }
public virtual void Preload() { if (_PreloadReady) { for (int i = 0; i < DepBundles.Count; ++i) { var bi = DepBundles[i]; if (bi == null || bi.Bundle == null) { _PreloadReady = false; break; } } } if (_PreloadReady) { return; } var oldbundles = new List <AssetBundleInfo>(DepBundles); DepBundles.Clear(); var opmod = ManiItem.Manifest.MFlag; var mod = opmod; if (ManiItem.Manifest.InMain) { mod = ""; } string bundle = ManiItem.BRef; if (string.IsNullOrEmpty(bundle)) { bundle = FormatBundleName(); } var cabi = LoadAssetBundleEx(mod, bundle, true); if (cabi != null) { AssetBundleManifest umani; if (UnityManifests.TryGetValue(mod, out umani) && umani) { var deps = umani.GetAllDependencies(bundle); if (deps != null) { for (int i = 0; i < deps.Length; ++i) { var dep = deps[i]; var bi = LoadAssetBundleEx(mod, dep, false); if (bi != null) { bi.AddRef(); DepBundles.Add(bi); } } } } cabi.AddRef(); DepBundles.Add(cabi); } for (int i = 0; i < oldbundles.Count; ++i) { var bi = oldbundles[i]; if (bi != null) { bi.Release(); } } _PreloadReady = true; }