Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - droptopgames

Pages: [1]
1
NGUI 3 Support / .cs questions ngui
« on: February 09, 2014, 03:42:57 PM »
Hello, i watched the tutorial video, still didn't really see my answer. I have created, and bunch already with ngui, but, integration on forms type gui has got me a little stumped. I have a basic login username and password and login button, ive created the ngui for login system. Original code was off unity gui, so just wondering what i need to add and remove to get this working. Just need to know per say how to get login input working with .cs then i'll have a structure to follow.

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class LoginUmaUI : MonoBehaviour
  7. {
  8.         public GUISkin skin;
  9.         public GameObject soundMenu;
  10.         public GameObject musicObject;
  11.  
  12.         enum LoginState
  13.         {
  14.                 Login,
  15.                 Register,
  16.                 Authenticating,
  17.                 CharacterSelect,
  18.                 CharacterCreate
  19.         }
  20.        
  21.         enum CreationState
  22.         {
  23.                 Body,
  24.                 Head,
  25.                 Face,
  26.                 Hair
  27.         }
  28.        
  29.         #region fields
  30.         LoginState loginState;
  31.         CreationState creationState;
  32.        
  33.         // Login fields
  34.         string username = "";
  35.         string password = "";
  36.        
  37.         // Registration fields
  38.         string password2 = "";
  39.         string email = "";
  40.         string email2 = "";
  41.        
  42.         // Character select fields
  43.         CharacterEntry characterSelected = null;
  44.         string characterName = "";
  45.         string race = "Human";
  46.         string gender = "Male";
  47.        
  48.         string dialogMessage = "";
  49.         string errorMessage = "";
  50.        
  51.         #endregion fields
  52.  
  53.         // Use this for initialization
  54.         void Start ()
  55.         {
  56.                 loginState = LoginState.Login;
  57.                 EventSystem.RegisterEvent("LOGIN_RESPONSE", this);
  58.                 EventSystem.RegisterEvent("REGISTER_RESPONSE", this);
  59.  
  60.                 // Play music
  61.                 SoundSystem.LoadSoundSettings();
  62.                 SoundSystem.PlayMusic(musicObject.GetComponent<AudioSource>());
  63.         }
  64.        
  65.         // Update is called once per frame
  66.         void Update ()
  67.         {
  68.        
  69.         }
  70.        
  71.         void OnGUI ()
  72.         {
  73.                 GUI.skin = skin;
  74.                
  75.                 if (errorMessage != "" || dialogMessage != "") {
  76.                         GUI.enabled = false;
  77.                 }
  78.                
  79.                 if (loginState == LoginState.Login || loginState == LoginState.Authenticating) {
  80.                         DrawLoginUI();
  81.                         //DrawSoundMenuButton();
  82.                 } else if (loginState == LoginState.Register) {
  83.                         DrawRegisterUI();
  84.                 }
  85.                
  86.                 GUI.enabled = true;
  87.                
  88.                 if (errorMessage != "") {
  89.                         DrawErrorUI();
  90.                 } else if (dialogMessage != "") {
  91.                         DrawDialogUI();
  92.                 }
  93.         }
  94.        
  95.         public void OnEvent(EventData eData) {
  96.                 if (eData.eventType == "LOGIN_RESPONSE") {
  97.                         dialogMessage = "";
  98.                         if (eData.eventArgs[0] == "Success") {
  99.                                 Application.LoadLevel("UMA Character Scene");
  100.                         } else {
  101.                                 errorMessage = eData.eventArgs[0];
  102.                         }
  103.                 } else if (eData.eventType == "REGISTER_RESPONSE") {
  104.                         dialogMessage = "";
  105.                         if (eData.eventArgs[0] == "Success") {
  106.                                 loginState = LoginState.Login;
  107.                                 errorMessage = "Account created. You can now log in";
  108.                         } else {
  109.                                 errorMessage = eData.eventArgs[0];
  110.                         }
  111.                 }
  112.         }
  113.        
  114.         Rect CreateCenteredRect (int width, int height)
  115.         {
  116.                 int left = (Screen.width - width) / 2;
  117.                 int top = (Screen.height - height) / 2;
  118.                 Rect centeredRect = new Rect (left, top, width, height);
  119.                 return centeredRect;
  120.         }
  121.        
  122.         void DrawLoginUI ()
  123.         {
  124.                 GUILayout.BeginArea(CreateCenteredRect (220, 180), skin.GetStyle("Window"));
  125.                 GUILayout.Label ("Username:");
  126.                 username = GUILayout.TextField (username);
  127.                 GUILayout.Label("Password:");
  128.                 password = GUILayout.PasswordField(password, '*');
  129.                 GUILayout.BeginHorizontal();
  130.                 if (GUILayout.Button("Login")) {
  131.                         dialogMessage = "Logging in...";
  132.                         // Verify username and password are entered, then pass them to the client
  133.                         // Also convert password to md5
  134.                         Client.Instance.Login(username, Encryption.Md5Sum(password));
  135.                 }
  136.  
  137.  
  138.                 GUILayout.EndHorizontal();
  139.                 GUILayout.EndArea();
  140.         }
  141.        
  142.        
  143.  
  144.        
  145.        
  146.         private bool ValidateEmail (string email)
  147.         {
  148.                 Regex regex = new Regex (@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
  149.                 Match match = regex.Match (email);
  150.                 if (match.Success)
  151.                         return true;
  152.                 else
  153.                         return false;
  154.         }
  155.         #endregion
  156.        
  157.         void ShowDialog(string message, bool showButton) {
  158.                 if (showButton) {
  159.                         errorMessage = message;
  160.                         dialogMessage = "";
  161.                 } else {
  162.                         dialogMessage = message;
  163.                         errorMessage = "";
  164.                 }
  165.                 /*dialogUI.SetActive(true);
  166.                 dialogString.text = message;
  167.                 dialogButton.SetActive(showButton);*/
  168.         }
  169. }

Im sure all the GUILayout stuff needs to go

  1. GUILayout.BeginArea(CreateCenteredRect (220, 180), skin.GetStyle("Window"));
  2.                 GUILayout.Label ("Username:");
  3.                 username = GUILayout.TextField (username);
  4.                 GUILayout.Label("Password:");
  5.                 password = GUILayout.PasswordField(password, '*');
  6.                 GUILayout.BeginHorizontal();
  7.                 if (GUILayout.Button("Login")) {
  8.                         dialogMessage = "Logging in...";
  9.                         // Verify username and password are entered, then pass them to the client
  10.                         // Also convert password to md5
  11.                         Client.Instance.Login(username, Encryption.Md5Sum(password));
  12.  


Kept really only the important parts of cs in pursuit of and quick explanation.

So do i just need the Ngui input fields to send there username and password strings over to my .cs?

What is needed for me to get my username and password strings from ngui over to my .cs source code file

Thanks

Pages: [1]