/// <summary> /// 延迟卸载,每帧检查 /// </summary> void DeferUnloadUpdate() { JWObjList <string> unloaded = null; var itor = _unloadingBundle.GetEnumerator(); while (itor.MoveNext()) { if (itor.Current.Value.Frame < 0) { if (unloaded == null) { unloaded = new JWObjList <string>(); } unloaded.Add(itor.Current.Key); DeferUnloadData.Recycle(itor.Current.Value); } else { itor.Current.Value.Frame--; } } for (int i = 0; unloaded != null && i < unloaded.Count; i++) { UnloadImmediately(unloaded[i]); _unloadingBundle.Remove(unloaded[i]); } }
public static void Recycle(DeferUnloadData data) { if (data != null) { data.Reset(); _pool.Add(data); } }
public static DeferUnloadData Get() { DeferUnloadData data = null; if (_pool.Count > 0) { data = _pool[_pool.Count - 1]; _pool.RemoveAt(_pool.Count - 1); } else { data = new DeferUnloadData(); } return(data); }
/// <summary> /// bundle资源已加载完 /// </summary> /// <param name="pi"></param> public void OnAssetLoaded(BundlePackInfo pi) { if (pi == null) { return; } // 立即卸载 (延帧) if (pi.Life == EBundleLife.Immediate) { if (!_unloadingBundle.ContainsKey(pi.Path)) { _unloadingBundle.Add(pi.Path, DeferUnloadData.Get()); } else { JW.Common.Log.LogE("Immediately unload bundle when it's already in unloading queue. bundle:{0}", pi.Path); } } }