Ejemplo n.º 1
0
 public EzGetScoreResult(
     GetScoreResult result
     )
 {
     if (result.item != null)
     {
         Item = new EzScore(result.item);
     }
 }
	// Get the scores from the MySQL DB to display in a GUIText.
	// remember to use StartCoroutine when calling this function!
	public static IEnumerator GetScores(int minDistance, int maxDistance, GetScoreResult callback)
	{
		string get_url = highscoreURL + "minDistance=" + minDistance + "&maxDistance=" + maxDistance + "&numScores=" + NumScoresRetrieved;

		WWW hs_get = new WWW(get_url);
		yield return hs_get;
		
		if (hs_get.error != null)
		{
			Debug.LogError("There was an error getting the high score: " + hs_get.error);
		}
		else
		{
			if (mScores == null)
			{
				mScores = new ScoreEntry[NumScoresRetrieved];
			}

			string[] scores = hs_get.text.Split('\n');
			string s;
			int i;
			int separator;
			int count = 0;
			for(i=0; i<scores.Length; ++i)
			{
				s = scores[i];

				separator = s.IndexOf("\t");

				if (s.Length > 0 && separator > 0)
				{
					mScores[i].Name = s.Substring(0, separator);
					mScores[i].Score = int.Parse(s.Substring(separator));
					++count;
				}
			}

			if (callback != null) callback(minDistance, maxDistance, mScores, count);
		}
	}