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

The UserItemsLobby screen displays a list of UserItems the User has obtained. When the User presses a button representing an UserItem, the UserItem screen is display.

The Start() method calls UserItemManager.GetAll() method to retrieve all UserItems the logged in User has obtained.

Together.Instance.User.UserItemManager.GetAll(onGotAllUserItems);

The DisplayButtons() method displays a button for every UserItem retrieved.

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

    //if( GUI.Button(new Rect((Screen.width - 200) * 0.5f, (Screen.height - 50 ) * 0.5f, 200, 50), "UserItem1"))
    //  Application.LoadLevel("UserItem");

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

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

if (GUI.Button(new Rect((Screen.width - buttonWidth) * 0.5f, 200 + (60 * i), buttonWidth, 50), display))
{
    Helper.UserData = m_userItems[i];
    Application.LoadLevel("UserItem");
}