Tic Tac Toe Example ChatroomLobby - TogetherGames/Public-Unity-CSharp GitHub Wiki

The ChatRoomLobby screen displays a list of ChatRooms configured in the game. The User can create a new ChatRoom or visit an existing ChatRoom by clicking on one of the ChatRoom buttons.

The Start() method calls ChatRoomManager.GetAll() method to retrieve all ChatRooms configured in the Game.

Together.Instance.ChatRoomManager.GetAll(0, onGotAllChatRooms);

The DisplayButtons() method displays a Create button and a list of ChatRoom buttons for all existing ChatRooms configured in the Game.

void DisplayButtons()
{
    if( GUI.Button(new Rect(10, 50, 100, 50), "Back"))
        Application.LoadLevel("MainMenu");

    if( GUI.Button(new Rect(10, 110, 100, 50), "Create Room"))
    {
        Debug.Log("Create room");   //Hack need to put in properties
        Together.Instance.ChatRoomManager.Create("TicTacToeTest",           // name
                                                 "Tic Tac Toe Chat!",       // description
                                                 0,                         // roomID
                                                 0,                         // gameInstanceID
                                                 false,                     // joinChatRoom
                                                 null,                      // chatRoomProperties
                                                 onCreatedRoom);            // callbackFunc
    }
    //if( GUI.Button(new Rect((Screen.width - 200) * 0.5f, 200, 200, 50), "ChatRoom1"))
    //  Application.LoadLevel("ChatRoom");

    if (m_bDisplay)
    {
        for (int i = 0; i < m_chatRooms.Length; i++)
        {
            string display = "ID= " + m_chatRooms[i].ChatRoomID + ", Name=" + m_chatRooms[i].Name;
            if( GUI.Button(new Rect((Screen.width - 400) * 0.5f, 200 +(60 * i), 400, 50), display))
            {
                Helper.UserData = m_chatRooms[i];
                Application.LoadLevel("ChatRoom");
            }
        }
    }
}

When the Create button is pressed, a new ChatRoom is created using the ChatRoomManager.Create() method.

When a ChatRoom button is pressed, the ChatRoom pressed is assigned to the Helper.UserData member before the ChatRoom scene is loaded. The Helper.UserData member is used to pass initialization data from one screen to another.