I'm using the FB SDK for Unity, and I'm finding it to be cumbersome with lost of callbacks due to async functions that need to be returned in sequence. How do I abstract my code so this is cleaner and seperate my logic / flow from the async callbacks?
My logic is this:
- If the player is not logged in, log them in (Async)
- If they are logged in, then check they have the right permissions (Async)
- If they don't have the right permissions, request them. (Async)
- Once they have the "post score" permissions, post the score. (Async)
Here's a pseudo example of what I'm trying to do:
Init()
{
LogInWithCallback(LoginResponse);
}
public LoginResponse(response)
{
if(response.loggedIn)
{
checkPermissions();
}
}
public checkPermissions(){
checkPermissionsWithCallback(permissionCheckCallback);
}
public permissionCheckCallback(ResponseDelegate)
{
//If the player doesn't have the right permissions, request them.
requestPermissions("score permission",permissionRequestCallback);
}
public permissionRequestCallback()
{
//if requesting the score permission was successful post score;
Postscore(); // <- It doesn't make sense to have logic which posts the player's score this deep down a callback chain, but I don't know any other way around.
}