Here is what I am trying to do:
I have a program that requires a player be logged into Facebook in order to perform certain functions. I have the Facebook login process which works by taking delegate as a parameter and then calling that delegate upon completion of the login with a bool value representing success or failure.
Here is where it gets a bit tricky. I want to fully encapsulate the login command within a class so that the user of the class does not have to worry about the login specifically when attempting to query data. For example, I have another function which retrieves the friends list of the user who is currently logged in. If the GetFriends function is called I would first like to check if a user is logged in and, if so, simply return the friends list which would have already been retrieved. However, if not logged in, this function will throw up the login prefab and wait for the user to log in. Once the user has done so it will then retrieve the friends list and return it back as the return value to the GetFriends function that initiated this process.
I have thought about having the user of the class check the login state first but this tends to get a bit messy with having to themselves create delegates and wait for the callback to ensure login occurred before being able to query friends. I would much prefer my class takes care of this.
I have attempted to do this with coroutines but have had difficulties returning the friends list back up to the original calling function. I have also had trouble getting a function whose type is not IEnumerator to wait for a coroutine to finish (in this case the coroutine is the login process). Can anyone suggest a good way to do what I’m asking? I really need the login to be handled by my class and not place this responsibility upon the user of my class.
To try to sum it up, I need this function:
public List<FacebookFriend> GetFriends()
to be able to login, if needed, and then return the friends list back.