private void setSpSprite(Image img, string name, SpriteRenderer renderer = null) { if (atlasCfg.ContainsKey(name)) { string bundleName = atlasCfg[name]; if (AssetMgr.isHave(bundleName)) { TBundle tb = AssetMgr.getBundle(bundleName); if (img != null) { img.sprite = tb.Ab.LoadAsset <Sprite>(name); } if (renderer != null) { renderer.sprite = tb.Ab.LoadAsset <Sprite>(name); } } else { //需要加载ab index++; SpriteTask spTask = new SpriteTask(index, name, bundleName, img, renderer); dictTask.Add(index, spTask); } } else { Debug.LogError("请导出图集配置"); } }
//www load IEnumerator wwwLoad() { //Debug.Log("加载资源" + url); status = E_LoadStatus.Loading; if (string.IsNullOrEmpty(url)) { status = E_LoadStatus.Fail; yield break; } //是否已经存在ab if (AssetMgr.isHave(url)) { for (int i = 0; i < handlerLst.Count; i++) { handlerLst[i].Invoke(url, true, AssetMgr.getBundle(url)); } status = E_LoadStatus.Finish; yield break; } //加载资源 AssetBundleCreateRequest abReq = AssetBundle.LoadFromFileAsync(Path.Combine(Application.dataPath, "Res/AssetBundle/" + url + ".assetbundle")); do { if (abReq.assetBundle == null) { status = E_LoadStatus.Fail; yield break; } yield return(new WaitForEndOfFrame()); } while (!abReq.isDone); AssetMgr.addBundle(url, abReq.assetBundle); for (int i = 0; i < handlerLst.Count; i++) { handlerLst[i].Invoke(url, true, AssetMgr.getBundle(url)); } status = E_LoadStatus.Finish; }
/// <summary> /// 加载clip /// </summary> /// <param name="path"></param> /// <param name="callBack"></param> private void loadClip(string path, Action <AudioClip> callBack) { if (AssetMgr.isHave(path)) { TBundle tb = AssetMgr.getBundle(path); if (callBack != null) { callBack(tb.Ab.LoadAsset <AudioClip>(getAudioName(path))); } } else { //需要加载ab if (tasks.ContainsKey(path)) { tasks[path].addHandler(callBack); } else { AudioTask task = new AudioTask(path, callBack); tasks.Add(path, task); } } }