-
Notifications
You must be signed in to change notification settings - Fork 2
How to use sharpchievements
Setting up achievementtracking with sharpchievements ist pretty easy.
You just need to register an Achievement
and some AchievementConditions
in the AchievementManager
and call AchievementManager.GetInstance().RegisterProgress("SomeConditionString");
Lets begin with creating an AchievementCondition
:
AchievementCondition aC = new AchievementCondition("This is the Titel", "aCKey", 5);
AchievementManager.GetInstance().RegisterAchievementCondition(aC);
An AchievmentCondition
describes what has to be done to progress in the completion of an achievement. AchievementCondition
instances are created with three parameters in the constructor:
-
The UniqueId The UniqueId is an... tadaa... unique identifier which... tadaa... uniquely identifies the
AchievementCondition
within theAchievementManager
. -
The Key The Key is used to track the progress of an
AchievementCondition
. The Key can be shared by multiple instances ofAchievementCondition
in order to track more than oneAchievementCondition
with only one action i.e. if you have anAchievement
for starting the program once and anotherAchievement
for starting the programm twice you can create two instances ofAchievementCondition
with the key "appStarted" and both would register a progress when the key is called. -
The Counter Defines how often a key has to be called to unlock the
AchievementCondition
.
Now after creating an AchievementCondition
and registering it in the AchievementManager
we need the Achievement
that we want to unlock by progressing with our AchievementCondition
:
Achievement a = new Achievement("a", "The Title", "The Description", aC, "/sebingel.sharpchievements;component/Images/award71.png");
AchievementManager.GetInstance().RegisterAchievement(a);
Achievement
instances are created with the following parameters:
-
The UniqueId As you may have guessed the UniqueId is an unique identifier which uniquely identifies the
Achievement
within theAchievementManager
. -
The Titel The Titel of the Achievement which should give a short description or the name of the
Achievement
object. The Titel is shown in theAchievementNotificationWindow
and theAchievementControl
. -
The Description The Description should be a more detailed description of the
Achievement
. It is also shown in theAchievementNotificationWindow
and theAchievementControl
. -
The
AchievementCondition
or aList<AchievementCondition>
At least oneAchievementCondition
is needed in order to be ale to unlock anAchievement
. -
The Imagepath (optional)
URI
or whatever to an image that is also shown in theAchievementNotificationWindow
and theAchievementControl
.
Now we have created an AchievementCondition
and an Achievement
and registered both with the AchievementManager
.
We are now ready and set to track some progress:
The AchievementManager
is a Singleton class that needs to know every Achievement
and every AchievementCondition
you want to track.
Tracking progress is as easy as AchievementManager.GetInstance().ReportProgress("aCkey")
. This reports progress for an AchievementCondition
with the key "aCkey".
Making progress with an AchievementCondition
counts toward the counter given in the constructor of the AchievementCondition
. When the counter reaches the given value the AchievementCondition
counts as unlocked. When every AchievementCondition
of an Achievement
is unlocked the Achievement
itself counts as unlocked.
When an Achievement
is unlocked the AchievementManager
fires the event AchievementCompleted
.
The AchievementManager
also provides a method to delete Achievements
: AchievementManager.GetInstance().DeleteAchievementByUniqueId("a")
deletes the Achievement
with the uniqueId "a" and AchievementManager.GetInstance().Reset()
deletes every registered Achievement
and every registered AchievementCondition
.
using sebingel.sharpchievements;
namespace MyAchievementTest
{
public class Program
{
static void Main()
{
AchievementManager am = AchievementManager.GetInstance();
AchievementCondition aC = new AchievementCondition("aC", "aCKey", 1);
AchievementManager.GetInstance().RegisterAchievementCondition(aC);
Achievement a = new Achievement("a", "The Title", "The Description", aC);
AchievementManager.GetInstance().RegisterAchievement(a);
am.RegisterAchievementCondition(aC);
am.RegisterAchievement(a);
am.ReportProgress("aCKey");
}
}
}
That is everything you need to track and unlock your first achievement!