Tic Tac Toe Example CustomRegistration - TogetherGames/Public-Unity-CSharp GitHub Wiki
The CustomRegistration screen when displayed allows the user to register with the Together system by providing merely an Email, Password, and Name.
The DisplayText() method displays several input fields allowing the User to specify the parameters for custom registration.
void DisplayText()
{
int labelY = 150;
int labelYStep = 40;
GUI.Label(new Rect((Screen.width - 500) * 0.5f, 15, 500, 50), "Custom Registration", m_TitleStyle);
GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 40), "Email:", m_TextStyle);
labelY += labelYStep - 15;
m_inEmail = GUI.TextField(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 25), m_inEmail);
labelY += labelYStep;
GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 40), "Password:", m_TextStyle);
labelY += labelYStep - 15;
m_inPassword = GUI.TextField(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 25), m_inPassword);
labelY += labelYStep;
GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 40), "Verify Password:", m_TextStyle);
labelY += labelYStep - 15;
m_inVerifyPassword = GUI.TextField(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 25), m_inVerifyPassword);
labelY += labelYStep;
GUI.Label(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 40), "Name:", m_TextStyle);
labelY += labelYStep - 15;
m_inName = GUI.TextField(new Rect((Screen.width - 300) * 0.5f, labelY, 300, 25), m_inName);
labelY += labelYStep;
}
The DisplayButtons() method displays the Register button. When the Register button is pressed, the input fields are verified before an attempt to register the User via the Together.RegisterCustom() method. In order for a registration attempt to be made, all input fields, (Email, Password, and Name), must at least be specified. The Password specified must also be the same as the VerifyPassword.
void DisplayButtons()
{
//Create and set the buttons
if( GUI.Button(new Rect(10, 50, 100, 50), "Back"))
Application.LoadLevel("Register");
if( GUI.Button(new Rect((Screen.width - 180) * 0.5f, Screen.height - 200, 180, 50), "Register"))
{
if(m_inEmail == "" || m_inName == "" || m_inPassword == "")
{
Helper.Popup("Uh oh", "All fields are required!", 0);
}
else
{
if (m_inPassword != m_inVerifyPassword)
{
Helper.Popup("Uh oh", "You must verify the password!", 0);
}
else
{
Debug.Log("Register custom user");
Together.Instance.RegisterCustom(m_inEmail, // email
m_inPassword, // password
m_inName, // name
onCustomRegistered); // callbackFunc
}
}
}
}