public UnityEngine.Object GetAsset(string name) { AssetRef assetRef = null; if (mRefDict.TryGetValue(name, out assetRef)) { return(assetRef.mAsset); } return(null); }
public IEnumerator LoadAsset(string name, System.Type type = null) { AssetRef assetRef = null; if (mRefDict.TryGetValue(name, out assetRef)) { while (!assetRef.mLoaded && assetRef.mAsset == null) { yield return(null); } yield break; } string bundleName; if (!mAsset2BundleDict.TryGetValue(name, out bundleName)) { LogManager.Debug("AssetManager::LoadAsset => can't find bundle name for asset " + name); yield break; } assetRef = new AssetRef(); if (assetRef == null) { yield break; } mRefDict.Add(name, assetRef); string[] dependencies = AssetBundleManager.Instance.GetAssetBundleDependencies(bundleName); Coroutine[] crtList = new Coroutine[dependencies.Length + 1]; crtList[crtList.Length - 1] = StartCoroutine(AssetBundleManager.Instance.LoadAssetBundle(bundleName)); for (int i = 0; i < dependencies.Length; ++i) { crtList[i] = StartCoroutine(AssetBundleManager.Instance.LoadAssetBundle(dependencies[i])); } int waitIndex = 0; while (waitIndex < crtList.Length) { yield return(crtList[waitIndex]); ++waitIndex; } AssetBundle ab = AssetBundleManager.Instance.GetAssetBundle(bundleName); if (ab != null) { AssetBundleRequest req = ab.LoadAssetAsync(name, type == null ? typeof(GameObject) : type); if (req != null) { yield return(req); assetRef.mAsset = req.asset; } } assetRef.mLoaded = true; AssetBundleManager.Instance.UnloadAssetBundle(bundleName); for (int i = 0; i < dependencies.Length; ++i) { AssetBundleManager.Instance.UnloadAssetBundle(dependencies[i]); } }