Skip to content

Instantly share code, notes, and snippets.

@kibotu
Created November 17, 2014 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kibotu/5745d401f26aec4e13cc to your computer and use it in GitHub Desktop.
Save kibotu/5745d401f26aec4e13cc to your computer and use it in GitHub Desktop.
Unlock Achievement with Promises
public override Promise unlockAchievements (string name, double points, bool autoStart = true)
{
var deferred = new Deferred<bool>();
string format = "Unlock Achievement " + name + " with " + points;
deferred.OnFulfilled += (bool result) => Debug.Log(format + ": " + result);
deferred.OnFailed += (bool result) => Debug.Log(format + ": " + result);
deferred.action += () =>
Social.ReportProgress(name, points, (bool success) => {
if(success)
deferred.Fulfill(success);
else
deferred.Fail(new Exception(format + " failed."));
});
return autoStart ? deferred.RunAsync() : deferred;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment