thieumao

Download 1 file Parse Unity

Oct 8th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using Parse;
  7.  
  8. public class ParseManager : MonoBehaviour {
  9.    
  10.     void Start () {
  11.         Download();
  12.     }
  13.  
  14.     public void Download(){
  15.         string id_facebook = "idfbtest";
  16.         string filename = "hinhanh.png";
  17.         StartCoroutine(LoadFile(id_facebook, filename));
  18.     }
  19.  
  20.     IEnumerator LoadFile(string id_facebook, string filename)   //single method downloads file
  21.     {
  22.         ParseQuery<ParseObject> query = ParseObject.GetQuery("Sync").WhereEqualTo("id_facebook", id_facebook);
  23.        
  24.         var queryTask = query.FirstAsync();
  25.         while (!queryTask.IsCompleted) yield return null;
  26.        
  27.         ParseObject obj = queryTask.Result;
  28.        
  29.         ParseFile pfile = obj.Get<ParseFile>("file_datauser");
  30.         int level = obj.Get<int>("level");
  31.         print ("level " + level);
  32.         Debug.Log(pfile.Url.AbsoluteUri);
  33.         WWW www = new WWW(pfile.Url.AbsoluteUri);
  34.         yield return www;
  35.         //Debug.Log("imageRequest " + imageRequest.text);
  36.         byte[] bytes = www.bytes;
  37.         String urlFile = Application.persistentDataPath + "/" + "ten" + level + ".png";//filename;
  38.         print ("duong dan: " + urlFile);
  39.         System.IO.File.WriteAllBytes(urlFile, bytes);
  40.  
  41.     }
  42.  
  43. }
Add Comment
Please, Sign In to add comment