Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Form with New UI System

Discussion in 'UGUI & TextMesh Pro' started by EdgarCarrera, Aug 22, 2014.

  1. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    Hello guys i want a make a logn system with UI System how i can make this?
     
  2. secondbreakfast

    secondbreakfast

    Joined:
    Jan 5, 2013
    Posts:
    98
    Watch the tutorial videos. They basically cover everything to make a simple form like login. The tutorial videos are linked off the beta download page.
     
  3. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    what video number?
     
  4. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    sakushin1 and Naruto45me like this.
  5. Zaladur

    Zaladur

    Joined:
    Oct 20, 2012
    Posts:
    392
    I would advise watching up through number 5 for the basics, though all of them are useful. Otherwise, ask yourself - what is a login form made up of? At the very basics, two text boxes and a 'login' button.
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I have a feeling where he's mainly running into trouble is using the username and password to actually login to a website; if so, the issues are not with understanding the UI system at all, but rather with the networking aspect of the task. (Incidentally, I tried and failed at that a while back using the WWW class, and would be interested in seeing how it's done)
     
  7. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    this is y script but i need add UI System

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Connection : MonoBehaviour
    5. {
    6.     public string username = "";
    7.     public string password= "";
    8.     public string repassword= "";
    9.     public string email= "";
    10.     public string message= "";
    11.     public GUISkin hdskin;
    12.     public int HofBox = 25;  
    13.     public string loguser= "";
    14.    
    15.     private string logpass= "";
    16.     private string logmessage= "";
    17.     private int generatednumber = 0;
    18.     private int numberinput;
    19.    
    20.     private bool islogin = true;
    21.     private bool isregister = false;
    22.    
    23.     private string CurrentMenu = "Menu";
    24.    
    25.     void  OnGUI ()
    26.     {
    27.         if(CurrentMenu == "Menu")
    28.         {
    29.             GUI.skin = hdskin;
    30.             if(islogin == false && isregister == true)
    31.             {
    32.                 GUI.Box( new Rect(Screen.width /2-250,20,500,480),"");
    33.                 GUI.Label( new Rect(Screen.width /2-100,30,200,50),"Please fill out the fields");
    34.                 GUI.Label( new Rect(Screen.width /2-230, 130,200,50),"Username:");
    35.                 username = GUI.TextField( new Rect(Screen.width /2-20,130,200,HofBox),username,45);
    36.                 GUI.Label( new Rect(Screen.width /2-230,190,200,50),"Password:");
    37.                 password = GUI.PasswordField( new Rect(Screen.width /2-20,190,200,HofBox),password,"*"[0],45);
    38.                 GUI.Label( new Rect(Screen.width /2-230,250,200,50),"Re-Enter pass:");
    39.                 repassword = GUI.PasswordField( new Rect(Screen.width /2-20,250,200,HofBox),repassword,"*"[0],45);
    40.                 GUI.Label( new Rect(Screen.width /2-230,310,200,50),"Email:");
    41.                 email = GUI.TextField( new Rect(Screen.width /2-20,310,200,HofBox),email,45);
    42.                 GUI.Label( new Rect(Screen.width /2-230,360,150,50),"Please verify:");
    43.                 GUI.Label( new Rect(Screen.width /2-80,360,100,HofBox),generatednumber.ToString());
    44.                 numberinput = int.Parse(GUI.TextField( new Rect(Screen.width /2+80,360,100,HofBox),numberinput.ToString()));
    45.                 if(GUI.Button( new Rect(Screen.width /2-230,420,200,HofBox),"Register!"))
    46.                 {
    47.                     message = "";  
    48.                     if(username == "" || email == "" || password == "" || numberinput == 0){
    49.                         message += "Please fill in the empty fields. \n";
    50.                     }else{
    51.                         if(password == repassword){
    52.                             if(numberinput == generatednumber){
    53.                                 StartCoroutine("doRegister");
    54.                             }else{
    55.                                 message += "The number you inputed is not the same number.";
    56.                             }
    57.                            
    58.                         }else{
    59.                             message += "The passwords do not match. \n";
    60.                         }
    61.                     }  
    62.                 }
    63.                 if(GUI.Button( new Rect(Screen.width /2-20,420,200,HofBox),"Return to login"))
    64.                 {
    65.                     islogin = true;
    66.                     isregister = false;
    67.                     username = ""; //cleaning our variables
    68.                     password = "";
    69.                     repassword = "";
    70.                     email = "";
    71.                     numberinput = 0;
    72.                     message = "";
    73.                     loguser = "";
    74.                     logpass = "";
    75.                     logmessage = "";
    76.                 }
    77.                 if(message != "")
    78.                 {
    79.                     GUI.Label( new Rect(Screen.width /2-230,460,460,50), message);
    80.                 }}
    81.             else if(islogin == true && isregister == false)
    82.             {
    83.                 StartCoroutine (ServerRefresh ());
    84.                
    85.                 GUI.Box( new Rect(Screen.width /2-250,20,500,450),"");
    86.                
    87.                 if(MasterServer.PollHostList().Length != 0)
    88.                 {
    89.                     HostData[] data = MasterServer.PollHostList();
    90.                     foreach(HostData c in data)
    91.                     {
    92.                         GUILayout.BeginArea(new Rect(Screen.width /2-65,30,200,50));
    93.                         GUILayout.Label(c.gameName + " " + (c.connectedPlayers - 1) + "/" + c.playerLimit);
    94.                         GUILayout.EndArea();
    95.                     }
    96.  
    97.                     //Login Button ///////////////////////////////////////////////////////////////////////////////////////
    98.                     if(GUI.Button( new Rect(Screen.width /2-230,330,200,HofBox),"Login")){
    99.                         if(loguser == "" || logpass == ""){
    100.                             logmessage += "Please enter the necessary data! \n";
    101.                         } else{
    102.                             logmessage = "";
    103.                             StartCoroutine("doLogin");
    104.                         }
    105.                     }
    106.                 }
    107.                 else
    108.                 {
    109.                     GUILayout.BeginArea(new Rect(Screen.width /2-65,30,200,50));
    110.                     GUI.color = Color.red;
    111.                     GUILayout.Label("Server Offline");
    112.                     GUI.color = Color.white;
    113.                     GUILayout.EndArea();
    114.                 }
    115.                
    116.                 GUI.Label( new Rect(Screen.width /2-230, 130,200,50),"Username:");
    117.                 loguser = GUI.TextField( new Rect(Screen.width /2-20,130,200,HofBox),loguser,45);
    118.                 GUI.Label( new Rect(Screen.width /2-230,230,200,50),"Password:");
    119.                 logpass = GUI.PasswordField( new Rect(Screen.width /2-20,230,200,HofBox),logpass,"*"[0],45);
    120.  
    121.  
    122.  
    123.  
    124.                 if(GUI.Button( new Rect(Screen.width /2-20,330,200,HofBox),"Register"))
    125.                 {
    126.                     islogin = false;
    127.                     isregister = true;
    128.                     generatednumber=Random.Range(1000,99999);
    129.                     username = ""; //cleaning our variables
    130.                     password = "";
    131.                     repassword = "";
    132.                     email = "";
    133.                     numberinput = 0;
    134.                     message = "";
    135.                     loguser = "";
    136.                     logpass = "";
    137.                     logmessage = "";
    138.                 }
    139.                 if(logmessage != "")
    140.                 {
    141.                     GUI.Label( new Rect(Screen.width /2-230,360,460,50),logmessage);
    142.                 }
    143.             }
    144.         }//CurrentMenu = Menu
    145.     }//OnGui
    146.    
    147.     public void OnConnectedToServer()
    148.     {
    149.         islogin = false;
    150.         isregister = false;
    151.         networkView.RPC("Login",RPCMode.All,loguser,Network.player);
    152.                
    153.         Application.LoadLevel (2);
    154.     }
    155.    
    156.     private void OnDisconnectedFromServer()
    157.     {
    158.         CurrentMenu = "Menu";
    159.     }
    160.    
    161.     private IEnumerator doRegister()
    162.     {
    163.         WWWForm form = new WWWForm();
    164.         form.AddField("Username" , username);
    165.         form.AddField("Password" , password);
    166.         form.AddField("Email" , email);          
    167.         var w = new WWW(Info.webSite + "/Register.php", form);          
    168.         yield return w;
    169.         if(w.error == null){
    170.             message += w.text;
    171.             StopCoroutine("doRegister");
    172.         }else{
    173.             message += "Error : " + w.error + "\n";
    174.         }
    175.     }
    176.     private IEnumerator doLogin()
    177.     {
    178.         WWWForm logform = new WWWForm();
    179.         logform.AddField("Username" , loguser);
    180.         logform.AddField("Password" , logpass);
    181.         var logw = new WWW(Info.webSite + "/Login.php", logform);
    182.         yield return logw;
    183.         if(logw.error == null){
    184.             logmessage += logw.text;
    185.  
    186.             StopCoroutine("doLogin");
    187.         }else{
    188.             logmessage +="Error : " + logw.error + "\n";  
    189.         }
    190.         if(logmessage == "Login success! Please wait while the game loads..."){
    191.             Network.Connect("avct.sytes.net", 8632);
    192.         }
    193.     }
    194.    
    195.     private IEnumerator ServerRefresh()
    196.     {
    197.         yield return new WaitForSeconds(3);
    198.         MasterServer.RequestHostList("MMOFPS");
    199.     }
    200.  
    201.     [RPC]
    202.     public void Login(string loguser,NetworkPlayer player)
    203.     {
    204.         Info.Owner = loguser;
    205.     }
    206. }
     
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Alright, so my guess was incorrect. So, watch the tutorials. They lay it out pretty clearly. If you have more specific questions about the tutorials, we'll be happy to help.
     
  9. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    already see al tutorials and no one have form
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    The tutorial isn't going to give you the exact thing you need. You're a human being with a functioning brain. You're gonna have to use it.

    Or, in other words: What specifically is missing from the tutorials that you don't understand how to do?
     
  11. Zaladur

    Zaladur

    Joined:
    Oct 20, 2012
    Posts:
    392
    Forms are not the UI component. Your text fields and buttons are. To integrate them with code, make sure to include

    Code (csharp):
    1. using UnityEngine.UI;
    Tutorials aren't custom tailored to entire pages - they tell you how to do each part. It is up to you to put it all together, just like you did with the old GUI in that script.
     
  12. nventimiglia

    nventimiglia

    Joined:
    Sep 20, 2011
    Posts:
    153
    Foundation includes a Login system. It has Signup, SignIn, Password Reset... the works.

    I am converting it to uGUI as we speak.
     
  13. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    how i can make text field with ui?
     
  14. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    Create InputField from create menu like Button.
     
  15. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    can u show me like picture? dont understand
     
  16. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    Untitled.png
    trolling++?
     
    EdgarCarrera likes this.
  17. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    ho S*** i dont see this buttons lol... thanks u
     
  18. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    That's strange. Don't they open those menus many times in the tutorial?
     
  19. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    sorry but i dont see this on the tutorials