void CreateLoadedAssetBundleCache(string assetBundleName, string assetName, System.Type type, UnityEngine.Object obj) { LoadedAssetBundleCache loaded = GetLoadedAssetBundleCache(assetBundleName, assetName, type); if (loaded != null) { loaded.obj = obj; loaded.referencedCount++; loaded.createCount++; } else { loaded = new LoadedAssetBundleCache(assetBundleName, assetName, type); loaded.obj = obj; if (!m_LoadedAssetBundleCaches.ContainsKey(assetBundleName)) { m_LoadedAssetBundleCaches.Add(assetBundleName, new Dictionary <string, Dictionary <System.Type, LoadedAssetBundleCache> >()); } if (!m_LoadedAssetBundleCaches[assetBundleName].ContainsKey(assetName)) { m_LoadedAssetBundleCaches[assetBundleName].Add(assetName, new Dictionary <System.Type, LoadedAssetBundleCache>()); } m_LoadedAssetBundleCaches[assetBundleName][assetName].Add(type, loaded); LoadedAssetBundleCacheList.Add(loaded); } }
public void UnloadAssetBundle(string assetBundleName, string assetName, System.Type type, int count, bool isSetLastTime) { LoadedAssetBundleCache loaded = GetLoadedAssetBundleCache(assetBundleName, assetName, type); if (loaded != null) { if (count < 0) { loaded.referencedCount = 0; } else { loaded.referencedCount -= count; } if (loaded.referencedCount <= 0) { if (isSetLastTime) { loaded.lastTime = Time.unscaledTime; } if (!AssetManagerSetting.UseCacheAssetTime) { UnloadLoadedAssetBundleCache(loaded); } } } else { manifestAssetBundleManager.UnloadAssetBundle(assetBundleName); } }
void UnloadLoadedAssetBundleCache(LoadedAssetBundleCache loaded) { // if (loaded.obj != null) // { // UnityEngine.Object.Destroy(loaded.obj); // } loaded.obj = null; for (int i = 0; i < loaded.createCount; i++) { manifestAssetBundleManager.UnloadAssetBundle(loaded.assetBundleName); } RemoveLoadedAssetBundleCache(loaded.assetBundleName, loaded.assetName, loaded.objType); }
//================= public void LoadAssetAsync(string filename, string assetBundleName, string assetName, System.Type type, Action <string, object, object[]> callback, params object[] callbackArgs) { if (assetBundleName.IndexOf("runerewardeffect") != -1) { Debug.Log(filename); } if (AssetManagerSetting.IsCacheAssetBundleAsset) { LoadedAssetBundleCache loaded = GetLoadedAssetBundleCache(assetBundleName, assetName, type); if (loaded != null) { loaded.referencedCount++; if (callback != null) { callback(filename, loaded.obj, callbackArgs); } return; } } StartCoroutine(OnLoadAssetAsync(filename, assetBundleName, assetName, type, callback, callbackArgs)); }