public void LoadAsset(string bundleName, string assetName, Action <Object> callBack) { // mark this bundle and asset //m_LruMgr.Access(bundleName); AssetBundleLoadInfo asset = new AssetBundleLoadInfo(); asset.m_strBundleName = bundleName; asset.m_strAssetName = assetName; string realName = bundleName + assetName; if (m_LoadedAssetMap.ContainsKey(realName)) { callBack(m_LoadedAssetMap[realName]); } else { if (m_AssetCallBackMap.ContainsKey(realName)) { m_AssetCallBackMap[realName] += callBack; } else { m_AssetCallBackMap.Add(realName, callBack); } m_CurrentLoadingAssetList.Enqueue(asset); } }
public void Clear() { m_CurrentLoadingAsset = null; m_CurrentLoadingAssetList.Clear(); m_CurrentLoadingBundleList.Clear(); m_AssetCallBackMap.Clear(); m_LoadedAssetMap.Clear(); foreach (var elem in m_LoadedBundleMap) { elem.Value.Unload(true); } m_LoadedBundleMap.Clear(); }
private IEnumerator LoadAssetFromBundle() { if (null == m_CurrentLoadingAsset) { yield break; } string realName = m_CurrentLoadingAsset.m_strBundleName + m_CurrentLoadingAsset.m_strAssetName; if (!m_AssetCallBackMap.ContainsKey(realName)) { // trigger to begin next download m_CurrentLoadingAsset = null; yield break; } if (!m_LoadedBundleMap.ContainsKey(m_CurrentLoadingAsset.m_strBundleName)) { Debug.LogError("error on load asset bundle " + m_CurrentLoadingAsset.m_strBundleName); yield break; } AssetBundle bundle = m_LoadedBundleMap[m_CurrentLoadingAsset.m_strBundleName]; Debug.Log("begin load asset " + m_CurrentLoadingAsset.m_strAssetName + " from bundle " + m_CurrentLoadingAsset.m_strBundleName); var request = bundle.LoadAssetAsync(m_CurrentLoadingAsset.m_strAssetName); yield return(request); if (null == request.asset) { Debug.LogError("Error on load asset " + m_CurrentLoadingAsset.m_strAssetName); } // broadcast resource if (m_LoadedAssetMap.ContainsKey(realName)) { m_LoadedAssetMap[realName] = request.asset; } else { m_LoadedAssetMap.Add(realName, request.asset); } var callBack = m_AssetCallBackMap[realName]; m_AssetCallBackMap.Remove(realName); callBack(request.asset); // trigger to begin next download m_CurrentLoadingAsset = null; }
void Update() { if (m_CurrentLoadingAsset == null && m_CurrentLoadingAssetList.Count > 0) { m_CurrentLoadingAsset = m_CurrentLoadingAssetList.Dequeue(); m_CurrentLoadingBundleList.Enqueue(m_CurrentLoadingAsset.m_strBundleName); BeginLoadAssetBundle(); } //if (m_RemovingBundleList.Count > 0) //{ // // do release bundle // int index = 3; // while (index <= 0 || m_RemovingBundleList.Count <= 0) // { // ReleaseAssetBundle(m_RemovingBundleList.Dequeue()); // -- index; // } //} }