Пример #1
0
        IEnumerator DownloadFeaturesCo(string feature, string outpath, Action next = null)
        {
            string MKey    = KeyProvider.GetMapZenKey();
            string FullURL = Paths.GetPath(ePATHSPEC.MAPZENURL);
            var    tileurl = TileX + "/" + TileZ;
            var    baseUrl = Paths.GetPath(ePATHSPEC.MAPZENURL);
            var    url     = baseUrl + feature + "/" + ZoomLevel + "/";

            FullURL = url + tileurl + ".json?api_key=" + MKey;

            string data = "";

            progress = 0;
            if (File.Exists(outpath))
            {
                Debug.Log("Cache Hit: " + outpath);
                data = File.ReadAllText(outpath);
            }
            else
            {
                Debug.Log(FullURL);
                WWW www = new WWW(FullURL);

                while (!www.isDone)
                {
                    progress = www.progress;
                    this.Repaint();
                    yield return(new WaitForSeconds(0.01f));
                }
                progress = 1;
                this.Repaint();
                //yield return www;

                if (string.IsNullOrEmpty(www.error))
                {
                    data = www.text;
                    File.WriteAllText(outpath, data);
                    AssetDatabase.Refresh();
                }
                else
                {
                    Debug.LogError(www.error);
                }
            }
            Done--;
            if (next != null)
            {
                next();
            }
        }
Пример #2
0
        IEnumerator DownloadNormalMapCo()
        {
            Debug.Log("Downloading Normap Map");

            if (File.Exists(Paths.GetPath(ePATHSPEC.NORMALMAPPATH)))
            {
                Debug.Log("Cache hit:" + Paths.GetPath(ePATHSPEC.NORMALMAPPATH));
                //Temp = AssetDatabase.LoadAssetAtPath<Texture2D>(GetPath(ePATHSPEC.TEXTUREPATH));
            }
            else
            {
                string FullURL = Paths.GetPath(ePATHSPEC.NORMALMAPURL);

                FullURL = FullURL.Replace("{mapzenkey}", KeyProvider.GetMapZenKey());
                FullURL = FullURL.Replace("{x}", TileX.ToString());
                FullURL = FullURL.Replace("{z}", TileZ.ToString());
                FullURL = FullURL.Replace("{zoom}", ZoomLevel.ToString());

                WWW wwwTex = new WWW(FullURL);
                yield return(wwwTex);

                if (!string.IsNullOrEmpty(wwwTex.error))
                {
                    Debug.Log("Error downloading from " + FullURL);
                    Done--;
                    yield break;
                }

                Texture2D Temp = new Texture2D((int)(cellsize), (int)(cellsize));
                wwwTex.LoadImageIntoTexture(Temp);

                string path = Paths.GetPath(ePATHSPEC.NORMALMAPPATH);
                File.WriteAllBytes(path, Temp.EncodeToPNG());
                DestroyImmediate(Temp);
                AssetDatabase.Refresh();

                TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;
                importer.textureType        = TextureImporterType.NormalMap;
                importer.wrapMode           = TextureWrapMode.Clamp;
                importer.textureCompression = TextureImporterCompression.Uncompressed;
                //      importer.isReadable = true;
                AssetDatabase.WriteImportSettingsIfDirty(path);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                Debug.Log("Downloaded Normap Map");
            }

            Done--;
        }