public BundleLoadTask(BundleHolder _holder, bool _assetSync = true) { holder = _holder; assetSync = _assetSync; loadCouroutine = Run(); BundleLoader.Instance.StartCoroutine(loadCouroutine); }
public void NoDelete(BundleHolder holder) { int index = waitingDelBundles.IndexOf(holder); if (index >= 0) { waitingDelBundles.RemoveAt(index); } }
//一次清除所有没有引用的bundle public void DeleteNoRefBundles() { for (int i = 0; i < waitingDelBundles.Count; ++i) { BundleHolder one = waitingDelBundles[i]; one.Unload(); } waitingDelBundles.Clear(); }
public void RefAsset(string assetPath) { BundleHolder holder = this.GetExistHolder(assetPath); if (null != holder) { holder.Ref(); } }
public void Cancel() { if (null != loadCouroutine) { BundleLoader.Instance.StopCoroutine(loadCouroutine); loadCouroutine = null; } holder = null; }
//直接获取已获得的资源,这种直接设置的情况,只限于它的引用关系已经根据bundle文件添加过了 //对于程序手动设置的,即在打包的时候并不存在这种依赖关系的,切勿用此接口,注意!!! public UnityEngine.Object GetExistAsset(string assetPath) { BundleHolder holder = this.GetExistHolder(assetPath); if (null != holder) { return(holder.MyAsset); } return(null); }
public void ReleaseAsset(string assetPath, bool delNow, int releasCount) { BundleHolder holder = GetExistHolder(assetPath); if (null != holder) { for (int i = 0; i < releasCount; ++i) { holder.UnRef(delNow); } } }
public void ReleaseAsset(string assetPath, bool delNow) { if (null == assetPath) { return; } BundleHolder holder = GetExistHolder(assetPath); if (null != holder) { holder.UnRef(delNow); } }
public UObj GetAssetSync(string assetPath) { BundleHolder holder = this.GetHolder(assetPath, false); if (null != holder) { if (!holder.IsLoaded()) { holder.LoadSync(); } return(holder.MyAsset); } return(null); }
//通过asset路径获取asset,cb是在获取后的回调,返回值是一个索引,用于取消获取 public ulong GetAsset(string assetPath, OnAssetGot cb, bool isManifest = false) { BundleHolder holder = this.GetHolder(assetPath, isManifest); if (null != holder) { return(holder.RefBy(cb)); } else { cb(null, 0); } return(0); }
public void CancelUngotAsset(ulong cbIdx) { AssetCallback acb = AssetCallback.Get(cbIdx); if (null == acb) { return; } BundleHolder holder = GetExistHolder(acb.Path); if (null != holder) { holder.UnRefBy(cbIdx); } }
/// <summary> /// 获取所有相关的holder,注意并不ref /// </summary> public void GetAllRelativeHolders(Dictionary <string, BundleHolder> holders) { if (!holders.ContainsKey(info.path)) { holders[info.path] = this; } if (null != info.depends) { for (int i = 0; i < info.depends.Length; ++i) { BundleHolder holder = mgr.GetHolder(info.depends[i]); if (null != holder) { holder.GetAllRelativeHolders(holders); } } } }
//获得holder public BundleHolder GetHolder(string bundlePath, bool isManifest = false) { if (bundles.ContainsKey(bundlePath)) { return(bundles[bundlePath]); } else { BundleInfo bi = depMap.GetInfo(bundlePath, isManifest); if (null != bi) { BundleHolder holder = BundleHolder.Gen(bi, this); bundles.Add(bundlePath, holder); return(holder); } else { return(null); } } }
//尝试少量的删除 public IEnumerator TryDelete() { yield return(null); float curTime = Time.realtimeSinceStartup; while (waitingDelBundles.Count > ZERO_REF_COUNT) { BundleHolder one = waitingDelBundles[0]; if (one.RefCount == 0 && curTime - one.NoRefTime > DEL_TIME) //它依赖的holder的时间肯定比它早 { one.Unload(); waitingDelBundles.RemoveAt(0); } else { break; //排在前面的时间最久 } } //_Scripts.Main.App.Log(string.Format("bundle count = {0}",bundles.Count)); }
public void AddDelete(BundleHolder holder) { waitingDelBundles.Add(holder); }