using System.Collections; using System.IO; using UnityEngine; public class LoadTilesFromAssetBundles : MonoBehaviour { private OnlineMaps map; private AssetBundleCreateRequest bundleLoadRequest; private AssetBundle myLoadedAssetBundle; private static bool logAllPaths = true; private void Start() { map = OnlineMaps.instance; // Subscribe to the tile download event. OnlineMapsTileManager.OnStartDownloadTile += OnStartDownloadTile; } private void OnStartDownloadTile(OnlineMapsTile tile) { StartCoroutine(LoadTile(tile)); } private IEnumerator LoadTile(OnlineMapsTile tile) { // Here your code to load tile texture from any source. if (myLoadedAssetBundle == null) { if (bundleLoadRequest == null) yield return LoadBundle(); else { while (myLoadedAssetBundle == null) { yield return null; } } } string path = string.Format("onlinemapstiles/{0}/{1}/{2}.png", tile.zoom, tile.x, tile.y); if (!myLoadedAssetBundle.Contains(path)) { tile.status = OnlineMapsTileStatus.error; } Texture2D tileTexture = myLoadedAssetBundle.LoadAsset(path); // Apply your texture in the buffer and redraws the map. if (map.control.resultIsTexture) { // Apply tile texture (tile as OnlineMapsRasterTile).ApplyTexture(tileTexture as Texture2D); // Send tile to buffer map.buffer.ApplyTile(tile); // Destroy the texture, because it is no longer needed. OnlineMapsUtils.Destroy(tileTexture); } else { // Send tile texture tile.texture = tileTexture; // Change tile status tile.status = OnlineMapsTileStatus.loaded; } // Redraw map (using best redraw type) map.Redraw(); } private IEnumerator LoadBundle() { bundleLoadRequest = AssetBundle.LoadFromFileAsync(Path.Combine(Application.persistentDataPath, "onlinemapstiles")); yield return bundleLoadRequest; myLoadedAssetBundle = bundleLoadRequest.assetBundle; string[] assetNames = myLoadedAssetBundle.GetAllAssetNames(); foreach (string s in assetNames) Debug.Log(s); } }