/// <summary> /// Reads the get one trophy response. /// </summary> /// <param name='response'> /// The response. /// </param> void ReadGetOneResponse(string response) { GJTrophy trophy; bool success = GJAPI.Instance.IsResponseSuccessful(response); if (!success) { GJAPI.Instance.GJDebug("Could not get the trophy.\n" + response, LogType.Error); trophy = null; } else { Dictionary <string, string> dictionary = GJAPI.Instance.ResponseToDictionary(response); GJAPI.Instance.CleanDictionary(ref dictionary); trophy = new GJTrophy(dictionary); GJAPI.Instance.GJDebug("Trophy successfully fetched.\n" + trophy.ToString()); } if (GetOneCallback != null) { GetOneCallback(trophy); } }
/// <summary> /// Reads the get all trophies response. /// </summary> /// <param name='response'> /// The response. /// </param> void ReadGetAllResponse(string response) { GJTrophy[] trophies; bool success = GJAPI.Instance.IsResponseSuccessful(response); if (!success) { GJAPI.Instance.GJDebug("Could not get the trophies.\n" + response, LogType.Error); trophies = null; } else { Dictionary <string, string>[] dictionaries = GJAPI.Instance.ResponseToDictionaries(response); GJAPI.Instance.CleanDictionaries(ref dictionaries); StringBuilder debug = new StringBuilder(); debug.Append("Trophies successfully fetched.\n"); int count = dictionaries.Length; trophies = new GJTrophy [count]; for (int i = 0; i < count; i++) { trophies [i] = new GJTrophy(dictionaries [i]); debug.Append(trophies [i].ToString()); } GJAPI.Instance.GJDebug(debug.ToString()); } if (GetAllCallback != null) { GetAllCallback(trophies); } }
private void OnGetRequestFinished(GJTrophy trophy) { if (trophy != null && !trophy.Achieved) { GJAPIHelper.Trophies.ShowTrophyUnlockNotification(trophy.Id); GJAPI.Trophies.Add(trophy.Id); } }
/// <summary> /// Check to see if given achievement has already been completed. /// </summary> public bool AchievementIsUnlocked(Achievement.Data data) { GJTrophy t = GetTrophy(data.id); if (t != null) { Debug.Log("Is achieved: " + data.title + ": " + t.Achieved); return(t.Achieved); } return(false); }
/// <summary> /// OnGetTrophy callback. /// </summary> /// <param name='trophy'> /// The trophy. /// </param> void OnGetTrophy(GJTrophy trophy) { GJAPI.Trophies.GetOneCallback -= OnGetTrophy; if (trophy != null) { DownloadTrophyIcon(trophy, tex => { GJHNotification nofitication = new GJHNotification(trophy.Title, trophy.Description, tex); GJHNotificationsManager.QueueNotification(nofitication); }); } }
/// <summary> /// Downloads the trophy icon. /// </summary> /// <param name='trophy'> /// The trophy. /// </param> /// <param name='OnComplete'> /// The callback. /// </param> public void DownloadTrophyIcon(GJTrophy trophy, Action <Texture2D> OnComplete) { GJAPIHelper.DownloadImage( trophy.ImageURL, icon => { if (icon == null) { icon = (Texture2D)Resources.Load("Images/TrophyIcon", typeof(Texture2D)) ?? new Texture2D(75, 75); } if (OnComplete != null) { OnComplete(icon); } }); }
/// <summary> /// Called when processing new data. /// </summary> public void AchievementProcessData(Achievement.Data data, int progress, bool complete) { GJTrophy t = GetTrophy(data.id); if (t != null) { mCurAchieveDat = data; t.Achieved = complete; GJAPI.Trophies.Add(t.Id); mState = State.Busy; } else { Debug.Log("Trophy id: " + data.id + " not found"); mCurAchieveDat = null; } }
/// <summary> /// Downloads the trophy icon. /// </summary> /// <param name='trophy'> /// The trophy. /// </param> /// <param name='OnComplete'> /// The callback. /// </param> public void DownloadTrophyIcon(GJTrophy trophy, Action<Texture2D> OnComplete) { GJAPIHelper.DownloadImage ( trophy.ImageURL, icon => { if (icon == null) { icon = (Texture2D) Resources.Load ("Images/TrophyIcon", typeof (Texture2D)) ?? new Texture2D (75,75); } if (OnComplete != null) { OnComplete (icon); } }); }
/// <summary> /// GetTrophies callback. /// </summary> /// <param name='t'> /// The trophies. /// </param> void OnGetTrophies(GJTrophy[] t) { GJAPI.Trophies.GetAllCallback -= OnGetTrophies; if (t == null) { SetWindowMessage ("Error loading trophies."); ChangeState (BaseWindowStates.Error.ToString ()); return; } trophies = t; int count = trophies.Length; trophiesIcons = new Texture2D[count]; for (int i = 0; i < count; i++) { trophiesIcons[i] = (Texture2D) Resources.Load ("Images/TrophyIcon", typeof (Texture2D)) ?? new Texture2D (75,75); int index = i; // If we pass i directly, it passes a reference and will be out of range. GJAPIHelper.Trophies.DownloadTrophyIcon ( trophies[i], icon => { trophiesIcons[index] = icon; }); } ChangeState (TrophiesWindowStates.TrophiesList.ToString ()); }
/// <summary> /// Reads the get one trophy response. /// </summary> /// <param name='response'> /// The response. /// </param> void ReadGetOneResponse(string response) { GJTrophy trophy; bool success = GJAPI.Instance.IsResponseSuccessful (response); if (!success) { GJAPI.Instance.GJDebug ("Could not get the trophy.\n" + response, LogType.Error); trophy = null; } else { Dictionary<string,string> dictionary = GJAPI.Instance.ResponseToDictionary (response); GJAPI.Instance.CleanDictionary (ref dictionary); trophy = new GJTrophy (dictionary); GJAPI.Instance.GJDebug ("Trophy successfully fetched.\n" + trophy.ToString()); } if (GetOneCallback != null) { GetOneCallback (trophy); } }
/// <summary> /// Reads the get multiple trophies response. /// </summary> /// <param name='response'> /// The response. /// </param> void ReadGetMultipleResponse(string response) { GJTrophy[] trophies; bool success = GJAPI.Instance.IsResponseSuccessful (response); if (!success) { GJAPI.Instance.GJDebug ("Could not get the trophies.\n" + response, LogType.Error); trophies = null; } else { Dictionary<string,string>[] dictionaries = GJAPI.Instance.ResponseToDictionaries (response); GJAPI.Instance.CleanDictionaries (ref dictionaries); StringBuilder debug = new StringBuilder(); debug.Append ("Trophies successfully fetched.\n"); int count = dictionaries.Length; trophies = new GJTrophy [count]; for (int i = 0; i < count; i++) { trophies [i] = new GJTrophy (dictionaries [i]); debug.Append (trophies [i].ToString ()); } GJAPI.Instance.GJDebug (debug.ToString ()); } if (GetMultipleCallback != null) { GetMultipleCallback (trophies); } }
/// <summary> /// OnGetTrophy callback. /// </summary> /// <param name='trophy'> /// The trophy. /// </param> void OnGetTrophy(GJTrophy trophy) { GJAPI.Trophies.GetOneCallback -= OnGetTrophy; if (trophy != null) { DownloadTrophyIcon (trophy, tex => { GJHNotification nofitication = new GJHNotification ( trophy.Title, trophy.Description, tex ); GJHNotificationsManager.QueueNotification (nofitication); }); } }