private void OnComplete(uint hash, UnityEngine.Object obj, bool isClone) { if (loadCB != null && obj != null) { if (isClone) { GameObject go = GameObject.Instantiate(obj) as GameObject; XResources.SetAsynAssetIndex(go.GetInstanceID(), hash); loadCB(go); } else { XResources.SetAsynAssetIndex(obj.GetInstanceID(), hash); loadCB(obj); } } }
public void AsynLoad <T>(string path, AssetType type, System.Action <Object> cb) where T : Object { uint hash = XCommon.singleton.XHash(path + type); AsynAsset asset; if (map.ContainsKey(hash) && map[hash].obt != null) //已经加载的 计数器加一 { map[hash].ref_cnt++; if (map[hash].is_clone_asset) { GameObject go = GameObject.Instantiate(map[hash].obt) as GameObject; XResources.SetAsynAssetIndex(go.GetInstanceID(), hash); cb(go); } else { cb(map[hash].obt); XResources.SetAsynAssetIndex(map[hash].obt.GetInstanceID(), hash); } } else if (IsAsynLoading(path, out asset)) //已正在加载的 回调cache { asset.cb.Add(cb); } else //没有加载的 开始加载 { AsynAsset node = new AsynAsset(); node.path = path; node.type = type; node.is_clone_asset = XResources.IsCloneAsset <T>(); node.request = Resources.LoadAsync <T>(path); node.cb = new List <System.Action <Object> >(); node.cb.Add(cb); asyn_list.Add(node); asyn_loading_cnt = asyn_list.Count; } }