IEnumerator DownloadHeightMapCo() { Debug.Log("Downloading Height Map"); if (File.Exists(Paths.GetPath(ePATHSPEC.HEIGHTMAPATH))) { Debug.Log("Cache hit:" + Paths.GetPath(ePATHSPEC.HEIGHTMAPATH)); //Temp = AssetDatabase.LoadAssetAtPath<Texture2D>(GetPath(ePATHSPEC.TEXTUREPATH)); yield return(new WaitForSeconds(0.1f)); } else { string FullURL = Paths.GetPath(ePATHSPEC.HEIGHTURL); FullURL = FullURL.Replace("{mapboxkey}", KeyProvider.GetMapBoxKey()); FullURL = FullURL.Replace("{x}", TileX.ToString()); FullURL = FullURL.Replace("{z}", TileZ.ToString()); FullURL = FullURL.Replace("{zoom}", ZoomLevel.ToString()); WWW wwwTex = new WWW(FullURL); while (!wwwTex.isDone) { progress = wwwTex.progress; Repaint(); yield return(new WaitForSeconds(0.1f)); } if (!string.IsNullOrEmpty(wwwTex.error)) { Debug.Log("Error downloading from " + FullURL); yield break; } Texture2D Temp = new Texture2D((int)(cellsize), (int)(cellsize)); wwwTex.LoadImageIntoTexture(Temp); //Color[] pixels = new Color[Temp.width * Temp.height]; //pixels = Temp.GetPixels(0, 0, Temp.width, Temp.height); string path = Paths.GetPath(ePATHSPEC.HEIGHTMAPATH); File.WriteAllBytes(path, Temp.EncodeToPNG()); //AssetDatabase.Refresh(); SwapImageForAsset(Temp, path); Debug.Log("Downloaded Height Map"); } HeightmapDone--; }
IEnumerator DownloadBasemapCo() { Debug.Log("Downloading Base Map"); int pixx = 0; int pixy = 0; //int Chop = 0; string FullURL = Paths.GetPath(ePATHSPEC.SATTELITEMAPURL); FullURL = FullURL.Replace("{mapboxkey}", KeyProvider.GetMapBoxKey()); FullURL = FullURL.Replace("{x}", TileX.ToString()); FullURL = FullURL.Replace("{z}", TileZ.ToString()); FullURL = FullURL.Replace("{zoom}", ZoomLevel.ToString()); Texture2D Temp; if (File.Exists(Paths.GetPath(ePATHSPEC.TEXTUREPATH))) { Debug.Log("Cache hit:" + Paths.GetPath(ePATHSPEC.TEXTUREPATH)); //Temp = AssetDatabase.LoadAssetAtPath<Texture2D>(GetPath(ePATHSPEC.TEXTUREPATH)); } else { Debug.Log(FullURL); Temp = new Texture2D((int)(cellsize), (int)(cellsize)); WWW wwwTex = new WWW(FullURL); yield return(wwwTex); if (!string.IsNullOrEmpty(wwwTex.error)) { //URL.text = ">>>>IMAGE>>" + wwwTex.error; Debug.Log("Error downloading from " + FullURL); Done--; yield break; } wwwTex.LoadImageIntoTexture(Temp); File.WriteAllBytes(Paths.GetPath(ePATHSPEC.TERRAINPATH) + "/texture.png", Temp.EncodeToPNG()); DestroyImmediate(Temp); AssetDatabase.Refresh(); Debug.Log("Downloaded Base Map"); } Done--; }