public Texture GetTexture(string assetName) { string assetPath = GetAssetPathByAssetName <Texture>(assetName); if (String.IsNullOrEmpty(assetName)) { // Debug.LogError("Null!"+assetName); return(null); } assetName = assetName.ToLower(); string bundleName = assetName + BytesExt; AddAssetBundleNameDic(assetPath, bundleName); BundleWrapper bundle = LoadBundle(bundleName); if (bundle.IsEmpty()) { return(null); } string[] names = bundle.GetAllAssetNames(); Texture sp = bundle.LoadAsset <Texture>(names[0]); return(sp); }
IEnumerator AsyncLoadCoroutine(string assetName, Action <SpriteAtlas> callBack) { string[] moduleNameParts = assetName.Split('_'); string moduleFolderName = moduleNameParts[0] + "_" + moduleNameParts[1]; BundleWrapper bundle = LoadBundle(moduleFolderName.ToLower() + AtlasExt); //yield return null; AssetBundleRequest req = bundle.LoadAllAssetsAsync(); if (req == null) { SpriteAtlas atlas1 = LoadAtlas(assetName); yield return(null); callBack(atlas1); yield break; } while (req.isDone == false) { yield return(null); } string[] names = bundle.GetAllAssetNames(); SpriteAtlas atlas = bundle.LoadAsset <SpriteAtlas>(names[0]); //yield return null; callBack(atlas); }
public AudioClip GetAudioClip(string assetName) { string assetPath = GetAssetPathByAssetName <AudioClip>(assetName); assetName = assetName.ToLower(); AddAssetBundleNameDic(assetPath, assetName + AudioExt); BundleWrapper bundle = LoadBundle(assetName + AudioExt); if (bundle.IsEmpty()) { return(null); } string[] names = bundle.GetAllAssetNames(); AudioClip ac = bundle.LoadAsset <AudioClip>(names[0]); return(ac); }
public ExternalBehaviorTree GetBehaviorTreeAsset(string assetName) { string assetPath = GetAssetPathByAssetName <TextAsset>(assetName); assetName = assetName.ToLower(); AddAssetBundleNameDic(assetPath, assetName + BytesExt); BundleWrapper bundle = LoadBundle(assetName + BytesExt); if (bundle.IsEmpty()) { return(null); } string[] names = bundle.GetAllAssetNames(); ExternalBehaviorTree ta = bundle.LoadAsset <ExternalBehaviorTree>(names[0]); return(ta); }
/// <summary> /// 加载图集 /// </summary> /// <param name="assetName"></param> /// <returns></returns> public SpriteAtlas LoadAtlas(string assetName) { string[] moduleNameParts = assetName.Split('_'); string moduleFolderName = moduleNameParts[0] + "_" + moduleNameParts[1]; #if UNITY_EDITOR && !USE_BUNDLE string assetPath = "Assets/BundleAssets/UISpriteAtlas/" + moduleFolderName + ".spriteatlas"; SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(assetPath); return(atlas); #else BundleWrapper bundle = LoadBundle(moduleFolderName.ToLower() + AtlasExt); bundle.LoadAllAssets(); string[] names = bundle.GetAllAssetNames(); SpriteAtlas atlas = bundle.LoadAsset <SpriteAtlas>(names[0]); return(atlas); #endif }
public Sprite GetSprite(string assetName) { string assetPath = GetAssetPathByAssetName <Texture>(assetName); assetName = assetName.ToLower(); string bundleName = assetName + BytesExt; AddAssetBundleNameDic(assetPath, bundleName); BundleWrapper bundle = LoadBundle <Sprite>(bundleName); if (bundle == null) { return(null); } string[] names = bundle.GetAllAssetNames(); Sprite sp = bundle.LoadAsset <Sprite>(names[0]); return(sp); }
public T GetAsset <T>(string assetName) where T : UnityEngine.Object { string asset_Path = GetAssetPathByAssetName <T>(assetName); assetName = assetName.ToLower(); UnityEngine.Object obj = null; bool useBundle = false; #if USE_BUNDLE useBundle = true; #endif if (_loadedAssets.ContainsKey(assetName) == false) { string assetKey = assetName + PrefabExt; AddAssetBundleNameDic(asset_Path, assetKey); if (_prefabDict.ContainsKey(assetKey) == false && useBundle) { // Debug.LogError("No Assets Found -> " + assetName); } else { BundleWrapper bundle = LoadBundle(assetKey); #if UNITY_EDITOR && !USE_BUNDLE string[] dps = AssetDatabase.GetAssetBundleDependencies(assetKey, true); LoadDependencies(dps); return((T)bundle.GetResource()); #endif string[] allAssetNames = bundle.GetAllAssetNames(); foreach (var assetPath in allAssetNames) { AssetItem aItem = new AssetItem() { AssetBundle = bundle.GetBundle(), AssetName = assetName, AssetPath = assetPath }; _loadedAssets.Add(assetName, aItem); } string[] dependencies = _manifest.GetAllDependencies(assetKey); LoadDependencies(dependencies); AssetItem item = _loadedAssets[assetName]; obj = item.AssetBundle.LoadAsset <T>(item.AssetPath); } } else { string assetKey = assetName + PrefabExt; string[] dependencies = _manifest.GetAllDependencies(assetKey); LoadDependencies(dependencies); AssetItem item = _loadedAssets[assetName]; obj = item.AssetBundle.LoadAsset <T>(item.AssetPath); } return((T)obj); }