public void TestAssetCache( ) { AssetCache cache = new AssetCache( ); int key = new Location( m_LocationManagers, "blarg" ).Key; // Add an asset to the cache object asset = new object( ); cache.Add( key, asset ); // Make sure that it can be retrived from its key Assert.AreEqual( asset, cache.Find( key ) ); // Collect garbage (will clean up asset) asset = null; GC.Collect( ); // Make sure that the asset is no longer in the cache Assert.AreEqual( cache.Find( key ), asset ); }
private UnityEngine.Object LoadBundle(string family, string bundlePathName, string assetName, bool persistent, AssetLoader.ObjectCallback callback, AssetLoader.OnDownloading onDownloading, object callbackData) { if (string.IsNullOrEmpty(assetName)) { return(null); } long num = TimeUtils.BinaryStamp(); Asset asset = Asset.Create(assetName, family, persistent, false, false); AssetCache.CachedAsset cachedAsset = new AssetCache.CachedAsset(); AssetCache.ObjectCacheRequest objectCacheRequest; if (!AssetCache.HasRequest(asset)) { objectCacheRequest = new AssetCache.ObjectCacheRequest(); AssetCache.AddRequest(asset, objectCacheRequest); } else { objectCacheRequest = AssetCache.GetRequest <AssetCache.ObjectCacheRequest>(asset); } objectCacheRequest.AddRequester(callback, onDownloading, callbackData); AssetCache.StartLoading(asset.Family.ToString()); if (AssetCache.HasItem(asset)) { cachedAsset = AssetCache.Find(asset); cachedAsset.LastRequestTimestamp = num; asset = cachedAsset.GetAsset(); } else if (this.m_assetBundleDict.ContainsKey(asset.Family) && this.m_assetBundleDict[asset.Family] != null) { if (!this.m_assetBundleDict[asset.Family].Contains(asset.Name)) { return(null); } UnityEngine.Object assetObject = this.m_assetBundleDict[family].Load(assetName, AssetBundleInfo.FamilyInfo[family].TypeOf); cachedAsset.SetAsset(asset); cachedAsset.SetAssetObject(assetObject); cachedAsset.CreatedTimestamp = num; cachedAsset.LastRequestTimestamp = num; AssetCache.Add(asset, cachedAsset); } else if (AssetCache.CanLoadBundle(asset.Family)) { this.LoadBundleFromDisk(asset, objectCacheRequest, cachedAsset); } if (cachedAsset.GetAssetObject() != null) { objectCacheRequest.OnProgressUpdate(assetName, 1f); objectCacheRequest.OnLoadSucceed(); objectCacheRequest.OnLoadComplete(assetName, cachedAsset.GetAssetObject()); AssetCache.RemoveRequest(asset); AssetCache.StopLoading(assetName); } return(cachedAsset.GetAssetObject()); }