diff --git a/Assets/Plugins/GameJolt/Scripts/API/Trophies.cs b/Assets/Plugins/GameJolt/Scripts/API/Trophies.cs index 1916314..2433649 100644 --- a/Assets/Plugins/GameJolt/Scripts/API/Trophies.cs +++ b/Assets/Plugins/GameJolt/Scripts/API/Trophies.cs @@ -32,12 +32,53 @@ public static void Unlock(int id, Action callback = null) cachedTrophies[id].Unlocked = response.success; } + // Show the notification + PrepareNotification(id); + if (callback != null) { callback(response.success); } }); } + + static void PrepareNotification(int id) + { + if (cachedTrophies != null && cachedTrophies.ContainsKey(id)) + { + if (cachedTrophies[id].Image != null) + { + ShowNotification(cachedTrophies[id]); + } + else + { + cachedTrophies[id].DownloadImage((bool success) => { + ShowNotification(cachedTrophies[id]); + }); + } + } + else + { + Get (id, (Objects.Trophy trophy) => { + if (trophy != null) + { + trophy.DownloadImage((bool success) => { + ShowNotification(trophy); + }); + } + }); + } + } + + static void ShowNotification(Objects.Trophy trophy) + { + if (trophy.Unlocked) + { + GameJolt.UI.Manager.Instance.QueueNotification( + string.Format("Unlocked #{0}", trophy.Title), + trophy.Image); + } + } #endregion Unlock #region Get