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

The ItemsLobby screen displays a list of Items configured in the game. Developers are resposible for creating and maintaining these Items. When the User presses a button representing an Item, the Item screen is display.

The Start() method calls ItemManager.GetAll() method to retrieve all game configured Items.

Together.Instance.ItemManager.GetAll(onGotAllItems);			// callbackFunc

The DisplayButtons() method displays a button for every Item configured in the Game.

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), "Item1"))
    //  Application.LoadLevel("Item");

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

When an Item button is pressed, the Item pressed is assigned to the Helper.UserData member before the Item 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_items[i];
    Application.LoadLevel("Item");
}