public ulong GetGameObj(string assetPath, OnGameObjGot cb) { if (unUsed.ContainsKey(assetPath)) { UnusedGo one = unUsed[assetPath]; GameObject go = one.Peek(); if (null != go) { cb(go, 0); return(0); } } if (string.IsNullOrEmpty(assetPath)) { GameObject go = new GameObject(); cb(go, 0); return(0); } GoCallback gcb = GenTask(assetPath, cb); gcb.AssetCbId = BundleMgr.Instance.GetAsset(assetPath, (asset, cbId) => { gcb.AssetCbId = 0; IEnumerator instant = Instant(gcb.Id, (UObj)asset); instanters.Add(gcb.Id, instant); StartCoroutine(instant); }); return(gcb.Id); }
//取消获取,reserve标识对于取消加载的对象是缓存到自己的缓冲池 //还是完全取消对象的加载 public void CancelUngotGameObj(ulong cbIdx, bool reserve) { GoCallback gcb = GoCallback.Get(cbIdx); if (null == gcb) { return; } if (goTasks.ContainsKey(gcb.Id)) { if (reserve && !unUsed.ContainsKey(gcb.Path))//需要缓存的情况 { gcb.Cb = (go, cbId) => { UnuseGameObj(gcb.Path, go); }; } else { goTasks.Remove(gcb.Id); GoCallback.Remove(gcb.Id); gcb.Cancel(); if (instanters.ContainsKey(gcb.Id)) { IEnumerator instanter = instanters[gcb.Id]; StopCoroutine(instanter); instanters.Remove(gcb.Id); } } } }
private GoCallback GenTask(string resPath, OnGameObjGot cb) { GoCallback gcb = GoCallback.Gen(cb, resPath); goTasks.Add(gcb.Id, gcb); return(gcb); }
public static GoCallback Gen(OnGameObjGot cb, string path) { GoCallback acb = new GoCallback(cb, path); items.Add(acb.Id, acb); return(acb); }
private void FinishInstant(ulong gcbId, GameObject go) { if (goTasks.ContainsKey(gcbId)) { GoCallback task = goTasks[gcbId]; task.Do(go); GoCallback.Remove(gcbId); goTasks.Remove(gcbId); } if (instanters.ContainsKey(gcbId)) { instanters.Remove(gcbId); } }