Logging Users In - TogetherGames/Public-Unity-CSharp GitHub Wiki
Due to the nature of client/server development, an error might occur at any time while the client waits for the server to respond to the client's request. Because of this, all calls to Together network methods should not attempt to assume success until the callback function is executed.
The following is an example of how a Game/Application could call the Together.Instance.LoginUser() method and process its response.
public void LoginUser()
{
Together.Instance.LoginUser(onLoggedIn);
}
public void onLoggedIn(PlaysTogether.TogetherCallback tcb)
{
Debug.Log("onLoggedIn "+ tcb);
if (tcb.Success)
{
Debug.Log(" Successfully logged in the user.");
Application.LoadLevel("MainMenu");
}
else
Helper.Popup("Uh oh", tcb.Message, 0);
}
When Togther.Instance.LoginUser() is called, the callback function onLoginUser() is passed in.
When the onLoginUser() callback function is executed, the Success member of TogetherCallback is examined to determine if an error occured. If an error occured, an error alert is immediately displayed. If the User was successfully logged in, the application enters the Main state.
In general, it is always good practice to wait for the response from the server before moving on to the next step.