/// <summary> /// 加载资源 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="abName"></param> /// <param name="objName"></param> /// <returns></returns> private T LoadFormAssetBundle <T>(string abName, string objName) where T : UnityEngine.Object { // T o = default(T); AssetBundleReference abr = null; if (assetbundleMap.TryGetValue(abName, out abr)) { o = abr.assetBundle.LoadAsset <T>(objName); } return(o); }
/// <summary> /// ab包计数器 /// </summary> /// <param name="name"></param> /// <param name="ab"></param> private void AddAssetBundle(string name, AssetBundle ab) { if (assetbundleMap.ContainsKey(name) == false) { AssetBundleReference abr = new AssetBundleReference() { assetBundle = ab }; assetbundleMap[name] = abr; } assetbundleMap[name].Use(); }
/// <summary> /// 检测资源 /// </summary> /// <param name="res"></param> /// <returns></returns> private AssetBundle CheckAsset(string res) { AssetBundleReference abr = null; //获取AssetBundle this.assetbundleMap.TryGetValue(res, out abr); if (abr.assetBundle != null) { return(abr.assetBundle); } return(null); }
/// <summary> /// 加入ab包 /// </summary> /// <param name="name"></param> /// <param name="ab"></param> private void UseAssetBunle(string name, AssetBundle ab) { name = Path.GetFileName(name); if (assetbundleMap.ContainsKey(name) == false) { AssetBundleReference abr = new AssetBundleReference() { assetBundle = ab }; assetbundleMap[name] = abr; } assetbundleMap[name].Use(); }
/// <summary> /// 加载资源 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="abName"></param> /// <param name="objName"></param> /// <returns></returns> private Object LoadFormAssetBundle(string objName, Type t) { //判断资源结构 是单ab-单资源、单ab-多资源 var mainItem = manifest.Manifest.GetManifestItem(objName); //单ab 单资源 var abName = objName; //单ab 多资源 if (mainItem != null && !string.IsNullOrEmpty(mainItem.PackageName)) { abName = mainItem.PackageName; } // if (!string.IsNullOrEmpty(abName)) { Object o = null; AssetBundleReference abr = null; if (assetbundleMap.TryGetValue(abName, out abr)) { if (abName.EndsWith(".spriteatlas")) { var atlas = abr.assetBundle.LoadAsset <SpriteAtlas>(abName); if (!objName.EndsWith(".spriteatlas")) { var name = Path.GetFileNameWithoutExtension(objName); o = atlas.GetSprite(name); } } else { o = abr.assetBundle.LoadAsset(objName, t); } } else { BDebug.Log("资源不存在:" + objName, "red"); return(null); } return(o); } return(null); }
/// <summary> /// ab包计数器 /// </summary> /// <param name="name"></param> /// <param name="ab"></param> private void AddAssetBundle(string name, AssetBundle ab) { //这里将路径前缀去除 var result = name.IndexOf("assets"); if (result != 0 && result > 0) { name = name.Substring(result); } // if (!assetbundleMap.ContainsKey(name)) { AssetBundleReference abr = new AssetBundleReference() { assetBundle = ab }; assetbundleMap[name] = abr; } assetbundleMap[name].Use(); }
/// <summary> /// 加载资源 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="abName"></param> /// <param name="objName"></param> /// <returns></returns> private T LoadFormAssetBundle <T>(string objName) where T : UnityEngine.Object { // if (!string.IsNullOrEmpty(objName)) { T o = default(T); AssetBundleReference abr = null; if (assetbundleMap.TryGetValue(objName, out abr)) { o = abr.assetBundle.LoadAsset <T>(objName); BDebug.Log("加载:" + objName); } else { BDebug.Log("资源不存在:" + objName); } return(o); } return(null); }