Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Show notifications on Trophy Unlock
Browse files Browse the repository at this point in the history
Close #40
  • Loading branch information
Loïc Teixeira committed Jul 1, 2015
1 parent 85ef55f commit f2c19e4
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Assets/Plugins/GameJolt/Scripts/API/Trophies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,53 @@ public static void Unlock(int id, Action<bool> 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 <b>#{0}</b>", trophy.Title),
trophy.Image);
}
}
#endregion Unlock

#region Get
Expand Down

0 comments on commit f2c19e4

Please sign in to comment.