/// <summary> /// 获取到某个资源 /// </summary> /// <param name="path">资源路径</param> /// <param name="onSucc">成功时的回调</param> /// <param name="onFail">失败时的回调</param> /// <param name="resType">资源类型,默认是UnKnow,如果是在bundle模式下,并且传入Unknow类型,会改成AssetBundle类型,如果text或AudioClip不打成bungle,必须传入类型,获取资源使用特定的方法</param> /// <returns>返回当前加载的Resource</returns> public Resource GetResource(string path, ResourceHandler onSucc = null, ResourceHandler onFail = null, ResourceType resType = ResourceType.UnKnow) { if (string.IsNullOrEmpty(path)) { CLog.LogError("[GetResource]ResName can not is null!"); return(null); } Resource res; _mapRes.TryGetValue(GetRealResourcePath(path), out res); if (res != null) { if (res.isDone) { if (res.isSucc && onSucc != null) { ResourceHandler tempOnSucc = onSucc; onSucc = null; tempOnSucc.Invoke(res, path); tempOnSucc = null; } } else { AddListener(res, path, onSucc, onFail); } return(res); } res = new Resource(); res.realPath = GetRealResourcePath(path); res.resType = (!DirectLoadMode && resType == ResourceType.UnKnow) ? ResourceType.AssetBundle : resType; //这个需要在加载依赖之前放入字典中(如果出现循环引用时需要直接获取) _mapRes.Add(res.realPath, res); res.Retain(); //获取到当前资源的依赖资源(可能没法保证顺序,所以拿的时候需要保证所有依赖资源都已经加载好) if (!DirectLoadMode && res.resType == ResourceType.AssetBundle) { string[] listDependResPath = GetDependResPath(path); if (listDependResPath != null && listDependResPath.Length > 0) { List <Resource> listDependRes = new List <Resource>(); for (int i = 0; i < listDependResPath.Length; i++) { //加载依赖资源 Resource dependRes = GetResource(listDependResPath[i]); listDependRes.Add(dependRes); } res.SetDependsRes(listDependRes); } } //真正加载当前资源 //_mapRes.Add(res.realPath, res); //res.Retain(); AddListener(res, path, onSucc, onFail); _resLoader.Load(res); return(res); }