static public T LoadAsset <T>(string assetBundleName, string assetName, System.Type type) where T : UnityEngine.Object { #if UNITY_EDITOR if (DevABModeInEditor) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName); return(null); } var t = AssetDatabase.LoadAssetAtPath <T>(assetPaths[0]); return(t as T); } else #endif { QLoadedAB bundle = null; Debug.Log(m_LoadedAssetBundles.Count + " ********** loadedassetbundles count******** " + assetBundleName); m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle); if (bundle.m_AssetBundle != null) { return(bundle.m_AssetBundle.LoadAsset <T> (assetName)); } else { Debug.LogError("***make sure the asset bundle finish loaded first *********"); return(null); } } }
// Where we actuall call WWW to download the assetBundle. static protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest) { // Already loaded. QLoadedAB bundle = null; m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle); if (bundle != null) { bundle.m_ReferencedCount++; return(true); } // @TODO: Do we need to consider the referenced count of WWWs? // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync(). // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs. if (m_DownloadingWWWs.ContainsKey(assetBundleName)) { return(true); } AssetBundleCreateRequest download = null; string url = m_BaseDownloadingURL + assetBundleName; download = AssetBundle.LoadFromFileAsync(url); m_DownloadingWWWs.Add(assetBundleName, download); return(false); }
public override bool Update() { if (m_Request != null) { return(false); } QLoadedAB bundle = QABMgr.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError); if (bundle != null) { if (m_IsAdditive) { m_Request = Application.LoadLevelAdditiveAsync(m_LevelName); } else { m_Request = Application.LoadLevelAsync(m_LevelName); } return(false); } else { return(true); } }
static public void ForceUnloadAll() { foreach (var keyValue in m_LoadedAssetBundles) { QLoadedAB loadedAb = keyValue.Value; loadedAb.m_AssetBundle.Unload(true); } m_LoadedAssetBundles.Clear(); m_DownloadingWWWs.Clear(); m_DownloadingErrors.Clear(); m_InProgressOperations.Clear(); m_Dependencies.Clear(); }
static protected AssetBundle LoadAssetBundleInternalSync(string assetBundleName, bool isLoadingAssetBundleManifest) { QLoadedAB bundle = null; m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle); if (bundle != null) { bundle.m_ReferencedCount++; return(bundle.m_AssetBundle); } string url = m_BaseDownloadingURL + assetBundleName; AssetBundle ab = AssetBundle.LoadFromFile(url); m_LoadedAssetBundles.Add(assetBundleName, new QLoadedAB(ab)); return(ab); }
static protected void UnloadAssetBundleInternal(string assetBundleName, bool force) { string error; QLoadedAB bundle = GetLoadedAssetBundle(assetBundleName, out error); if (bundle == null) { return; } if (--bundle.m_ReferencedCount == 0) { bundle.m_AssetBundle.Unload(force); m_LoadedAssetBundles.Remove(assetBundleName); Log(LogType.Info, assetBundleName + " has been unloaded successfully"); } }
// Returns true if more Update calls are required. public override bool Update() { if (m_Request != null) { return(false); } QLoadedAB bundle = QABMgr.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError); if (bundle != null) { ///@TODO: When asset bundle download fails this throws an exception... m_Request = bundle.m_AssetBundle.LoadAssetAsync(m_AssetName, m_Type); return(false); } else { return(true); } }
// Returns true if more Update calls are required. public override bool Update() { if (loadFinish) { return(false); } bundle = QABMgr.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError); if (bundle != null) { ///@TODO: When asset bundle download fails this throws an exception... loadFinish = true; return(false); } else { return(true); } }
// Get loaded AssetBundle, only return vaild object when all the dependencies are downloaded successfully. static public QLoadedAB GetLoadedAssetBundle(string assetBundleName, out string error) { if (m_DownloadingErrors.TryGetValue(assetBundleName, out error)) { return(null); } QLoadedAB bundle = null; m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle); if (bundle == null) { return(null); } // No dependencies are recorded, only the bundle itself is required. string[] dependencies = null; if (!m_Dependencies.TryGetValue(assetBundleName, out dependencies)) { return(bundle); } // Make sure all dependencies are loaded foreach (var dependency in dependencies) { if (m_DownloadingErrors.TryGetValue(assetBundleName, out error)) { return(bundle); } // Wait all the dependent assetBundles being loaded. QLoadedAB dependentBundle; m_LoadedAssetBundles.TryGetValue(dependency, out dependentBundle); if (dependentBundle == null) { return(null); } } return(bundle); }