Advertisement
Guest User

Untitled

a guest
Nov 12th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1.     private void OnStartDownloadTile(OnlineMapsTile tile)
  2.     {
  3.         tile.status = OnlineMapsTileStatus.loading;
  4.         string filePath = Path.Combine(Application.persistentDataPath, tile.resourcesPath + ".png");
  5.         if (File.Exists(filePath))
  6.         {
  7.             StartCoroutine(TryLoadFromResources(tile, filePath));
  8.         }
  9.         else
  10.         {
  11.             if (isMapOnline)
  12.             {
  13.                 OnlineMapsTileManager.StartDownloadTile(tile);
  14.             }
  15.             else
  16.             {
  17.                 tile.status = OnlineMapsTileStatus.error;
  18.             }
  19.         }
  20.     }
  21.    
  22.     private IEnumerator TryLoadFromResources(OnlineMapsTile tile, string path)
  23.     {
  24.         var req = UnityWebRequestTexture.GetTexture(path);
  25.         yield return req.SendWebRequest();
  26.         if (tile.map == null)
  27.         {
  28.             tile.MarkError();
  29.             yield break;
  30.         }
  31.         Texture2D texture = DownloadHandlerTexture.GetContent(req);
  32.         if (texture != null)
  33.         {
  34.             texture.wrapMode = TextureWrapMode.Clamp;
  35.             if (tile.map.control.resultIsTexture)
  36.             {
  37.                 (tile as OnlineMapsRasterTile).ApplyTexture(texture);
  38.                 tile.map.buffer.ApplyTile(tile);
  39.                 OnlineMapsUtils.Destroy(texture);
  40.             }
  41.             else
  42.             {
  43.                 tile.texture = texture;
  44.                 tile.status = OnlineMapsTileStatus.loaded;
  45.             }
  46.             tile.MarkLoaded();
  47.             //tile.loadedFromResources = true;
  48.             tile.map.Redraw();
  49.         }
  50.         else if (tile.map.source == OnlineMapsSource.Resources)
  51.         {
  52.             tile.MarkError();
  53.         }
  54.         req.Dispose();
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement