Advertisement
Guest User

Untitled

a guest
Oct 16th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using GooglePlayGames;
  4. using UnityEngine.SocialPlatforms;
  5.  
  6. public class SalvarWeb : MonoBehaviour {
  7.     //public TextMesh User;
  8.     public string url = "http://xtremelevel.net/Alka/ES2.php";
  9.     public string username;
  10.     public static string filename = "";
  11.     public string webUsername = "ES2";
  12.     public string webPassword = "65w84e4p994z3Oq";
  13.     //public string UserName;
  14.     public int[] intArray;
  15.     public int[] Check;
  16.     private string VariableGuardar;
  17.  
  18.  
  19.  
  20.     // Use this for initialization
  21.     void Awake () {
  22. #if UNITY_ANDROID
  23.    
  24.      filename = Social.localUser.userName + ".txt";
  25. #endif
  26.     //UserName  = "Usuario"; // UserName
  27.     //filename = UserName + ".txt";
  28.         //UserID      = Social.localUser.id; // UserID
  29.         //ProfilePic    =Social.localUser.image; // ProfilePic
  30.     }
  31.     public void Descargar(){
  32.  
  33.         StartCoroutine ("Download", "Datos");
  34.     }
  35.     public void Subir(){
  36.         StartCoroutine ("Upload", "Datos");
  37.     }
  38.     public IEnumerator Upload(string tag)
  39.     {
  40.         username = Social.localUser.userName;
  41.         filename = username + ".txt";
  42.         string myURL = "http://xtremelevel.net/Alka/ES2.php?";
  43.         myURL += "webfilename=" + filename + "&webusername="+webUsername + "&webpassword=" +webPassword;
  44.         Debug.Log (myURL + "&tag=" + tag);
  45.         ES2Web web = new ES2Web(myURL + "&tag=" + tag);
  46.         intArray [0] = Estadodejuego.estadojuego.puntacionMaxima;
  47.         intArray [1] = Estadodejuego.estadojuego.puntacionMaxima1;
  48.         intArray [2] = Estadodejuego.estadojuego.puntacionMaxima2;
  49.         intArray [3] = Estadodejuego.estadojuego.puntacionMaxima3;
  50.         intArray [4] = Estadodejuego.estadojuego.puntacionMaxima4;
  51.    
  52.    
  53.  
  54.  
  55.         // Start uploading our data and wait for it to finish.
  56.         yield return StartCoroutine(web.UploadRaw(intArray));
  57.        
  58.         if(web.isError)
  59.         {
  60.             // Enter your own code to handle errors here.
  61.             // For a list of error codes, see the ES2Web Error Codes Page.
  62.             Debug.LogError(web.errorCode + ":" + web.error);
  63.         }
  64.     }
  65.     public IEnumerator Download(string tag)
  66.     {
  67.         yield return new WaitForSeconds (2);
  68.         username = Social.localUser.userName;
  69.         filename = username + ".txt";
  70.         string myURL = "http://xtremelevel.net/Alka/ES2.php?";
  71.         myURL += "webfilename=" + filename + "&webusername="+webUsername + "&webpassword=" +webPassword;
  72.         Debug.Log (myURL + "&tag=" + tag);
  73.         ES2Web web = new ES2Web(myURL + "&tag=" + tag);
  74.        
  75.         // Start uploading our data and wait for it to finish.
  76.         yield return StartCoroutine(web.Download());
  77.        
  78.         if(web.isError)
  79.         {
  80.             // Enter your own code to handle errors here.
  81.             // For a list of error codes, see the ES2Web Error Codes Page.
  82.             Debug.LogError(web.errorCode + ":" + web.error);
  83.         }
  84.         // Now save our data to file so we can use ES2.Load to load it later.
  85.         web.SaveToFile (filename);
  86.         Check = ES2.LoadArray<int> ( filename +"?tag=Datos");
  87.         Estadodejuego.estadojuego.puntacionMaxima = Check [0];
  88.         Estadodejuego.estadojuego.puntacionMaxima1 = Check [1];
  89.         Estadodejuego.estadojuego.puntacionMaxima2 = Check [2];
  90.         Estadodejuego.estadojuego.puntacionMaxima3 = Check [3];
  91.         Estadodejuego.estadojuego.puntacionMaxima4 = Check [4];
  92.     }
  93.    
  94.     // Update is called once per frame
  95.  
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement