Tic Tac Toe Example FriendLobby - TogetherGames/Public-Unity-CSharp GitHub Wiki
The FriendLobby screen displays a list of Together Friends and Facebook Friends. Facebook Friends will only be displayed though if you have logged into Facebook.
The Start() method calls FriendUserManager.GetAll() method to retrieve all Together friends.
Together.Instance.FriendUserManager.GetAll(onGotTogetherFriends);
The DisplayText() method displays all the Together friends and Facebook friends.
void DisplayText()
{
//Create and set the labels
GUI.Label(new Rect((Screen.width - 600) * 0.5f, 15, 600, 50), "Select Friend to Invite to " + FriendLobby.PreviousScreen, m_TitleStyle);
GUI.DrawTexture(new Rect(Screen.width - 148, Screen.height - 148, 128, 128), FacebookTexture, ScaleMode.ScaleToFit, true);
int labelWidth = 400;
int i;
PlaysTogether.FriendUser togetherFriend;
PlaysTogether.ExternalFriend facebookFriend;
int labelY = 80;
string buttonLabel = "";
GUI.Label(new Rect((Screen.width - labelWidth) * 0.5f, labelY, labelWidth, 50), "Together Friends", m_TextStyle);
labelY += 30;
for (i=0; i<=Together.Instance.FriendUserManager.GetCount()-1; i++)
{
togetherFriend = Together.Instance.FriendUserManager.Get(i);
buttonLabel = "UserID=" + togetherFriend.UserID + ", Name=" + togetherFriend.Name;
if (GUI.Button(new Rect((Screen.width - labelWidth) * 0.5f, labelY, labelWidth, 50), buttonLabel))
OnTogetherFriendButtonClicked(togetherFriend);
labelY += 30;
}
buttonLabel = "UserID=123456, Name=user_123456";
if (GUI.Button(new Rect((Screen.width - labelWidth) * 0.5f, labelY, labelWidth, 50), buttonLabel))
OnTogetherFriendButtonClicked(null);
labelY += 30;
labelY += 30;
GUI.Label(new Rect((Screen.width - labelWidth) * 0.5f, labelY, labelWidth, 50), "-------------------------------------", m_TextStyle);
labelY += 30;
GUI.Label(new Rect((Screen.width - labelWidth) * 0.5f, labelY, labelWidth, 50), "Facebook Friends", m_TextStyle);
labelY += 30;
/* for (i=0; i<=Together.Instance.Social.Facebook.GetFacebookFriendCount()-1; i++) { facebookFriend = Together.Instance.Social.Facebook.GetFacebookFriend(i);
if (GUI.Button(new Rect(260, labelY, 300, 50), "UserID=" + facebookFriend.FriendID + ", Name=" + facebookFriend.Name))
OnFacebookFriendButtonClicked(facebookFriend);
labelY += 30;
}
*/
buttonLabel = buttonLabel = "FacebookID=123456789000, Name=Josh Blahblahblah";
if (GUI.Button(new Rect((Screen.width - labelWidth) * 0.5f, labelY, labelWidth, 50), buttonLabel))
OnFacebookFriendButtonClicked(null);
}
When a Together friend is pressed, the OnTogetherFriendButtonClicked() method is called. The OnTogetherFriendButtonClicked() will either attempt to invite the User to current ChatRoom or current GameInstance, depending which spawned the FriendLobby screen.
void OnTogetherFriendButtonClicked(PlaysTogether.FriendUser togetherFriend)
{
Debug.Log("FriendLobby.OnTogetherFriendButtonClicked()");
if (togetherFriend == null)
return;
m_TogetherFriend = togetherFriend;
// If the previous screen was the 'GameInstance' screen, then invite the User to the GameInstance.
if (FriendLobby.PreviousScreen == "GameInstance")
{
m_GameInstance = Helper.UserData as PlaysTogether.GameInstance;
InviteTogetherFriendToGameInstance();
}
// If the previous screen was the 'ChatRoom' screen, then invite the User to the ChatRoom.
else if (FriendLobby.PreviousScreen == "ChatRoom")
{
m_ChatRoom = Helper.UserData as PlaysTogether.ChatRoom;
InviteTogetherFriendToChatRoom();
}
}
When a Facebook friend is pressed, the OnFacebookFriendButtonClicked() method is called. The OnFacebookFriendButtonClicked() will either attempt to send a WallPost to a Facebook Users' Wall inviting them either to the current GameInstance or current ChatRoom, depending which spawned the FriendLobby screen.
void OnFacebookFriendButtonClicked(PlaysTogether.ExternalFriend facebookFriend)
{
Debug.Log("FriendLobby.OnFacebookFriendButtonClicked()");
if (facebookFriend == null)
return;
m_FacebookFriend = facebookFriend;
// If the previous screen was the 'GameInstance' screen, then send a Facebook Post to the user
// inviting them to the GameInstance.
if (FriendLobby.PreviousScreen == "GameInstance")
{
m_GameInstance = Helper.UserData as PlaysTogether.GameInstance;
InviteFacebookFriendToGameInstance();
}
// If the previous screen was the 'ChatRoom' screen, then invite the User to the ChatRoom.
else if (FriendLobby.PreviousScreen == "ChatRoom")
{
m_ChatRoom = Helper.UserData as PlaysTogether.ChatRoom;
InviteFacebookFriendToChatRoom();
}
}