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.
Im sure all the GUILayout stuff needs to go
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
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public class LoginUmaUI : MonoBehaviour
- {
- public GUISkin skin;
- public GameObject soundMenu;
- public GameObject musicObject;
- enum LoginState
- {
- Login,
- Register,
- Authenticating,
- CharacterSelect,
- CharacterCreate
- }
- enum CreationState
- {
- Body,
- Head,
- Face,
- Hair
- }
- #region fields
- LoginState loginState;
- CreationState creationState;
- // Login fields
- string username = "";
- string password = "";
- // Registration fields
- string password2 = "";
- string email = "";
- string email2 = "";
- // Character select fields
- CharacterEntry characterSelected = null;
- string characterName = "";
- string race = "Human";
- string gender = "Male";
- string dialogMessage = "";
- string errorMessage = "";
- #endregion fields
- // Use this for initialization
- void Start ()
- {
- loginState = LoginState.Login;
- EventSystem.RegisterEvent("LOGIN_RESPONSE", this);
- EventSystem.RegisterEvent("REGISTER_RESPONSE", this);
- // Play music
- SoundSystem.LoadSoundSettings();
- SoundSystem.PlayMusic(musicObject.GetComponent<AudioSource>());
- }
- // Update is called once per frame
- void Update ()
- {
- }
- void OnGUI ()
- {
- GUI.skin = skin;
- if (errorMessage != "" || dialogMessage != "") {
- GUI.enabled = false;
- }
- if (loginState == LoginState.Login || loginState == LoginState.Authenticating) {
- DrawLoginUI();
- //DrawSoundMenuButton();
- } else if (loginState == LoginState.Register) {
- DrawRegisterUI();
- }
- GUI.enabled = true;
- if (errorMessage != "") {
- DrawErrorUI();
- } else if (dialogMessage != "") {
- DrawDialogUI();
- }
- }
- public void OnEvent(EventData eData) {
- if (eData.eventType == "LOGIN_RESPONSE") {
- dialogMessage = "";
- if (eData.eventArgs[0] == "Success") {
- Application.LoadLevel("UMA Character Scene");
- } else {
- errorMessage = eData.eventArgs[0];
- }
- } else if (eData.eventType == "REGISTER_RESPONSE") {
- dialogMessage = "";
- if (eData.eventArgs[0] == "Success") {
- loginState = LoginState.Login;
- errorMessage = "Account created. You can now log in";
- } else {
- errorMessage = eData.eventArgs[0];
- }
- }
- }
- Rect CreateCenteredRect (int width, int height)
- {
- int left = (Screen.width - width) / 2;
- int top = (Screen.height - height) / 2;
- return centeredRect;
- }
- void DrawLoginUI ()
- {
- GUILayout.BeginArea(CreateCenteredRect (220, 180), skin.GetStyle("Window"));
- GUILayout.Label ("Username:");
- username = GUILayout.TextField (username);
- GUILayout.Label("Password:");
- password = GUILayout.PasswordField(password, '*');
- GUILayout.BeginHorizontal();
- if (GUILayout.Button("Login")) {
- dialogMessage = "Logging in...";
- // Verify username and password are entered, then pass them to the client
- // Also convert password to md5
- Client.Instance.Login(username, Encryption.Md5Sum(password));
- }
- GUILayout.EndHorizontal();
- GUILayout.EndArea();
- }
- private bool ValidateEmail (string email)
- {
- Match match = regex.Match (email);
- if (match.Success)
- return true;
- else
- return false;
- }
- #endregion
- void ShowDialog(string message, bool showButton) {
- if (showButton) {
- errorMessage = message;
- dialogMessage = "";
- } else {
- dialogMessage = message;
- errorMessage = "";
- }
- /*dialogUI.SetActive(true);
- dialogString.text = message;
- dialogButton.SetActive(showButton);*/
- }
- }
Im sure all the GUILayout stuff needs to go
- GUILayout.BeginArea(CreateCenteredRect (220, 180), skin.GetStyle("Window"));
- GUILayout.Label ("Username:");
- username = GUILayout.TextField (username);
- GUILayout.Label("Password:");
- password = GUILayout.PasswordField(password, '*');
- GUILayout.BeginHorizontal();
- if (GUILayout.Button("Login")) {
- dialogMessage = "Logging in...";
- // Verify username and password are entered, then pass them to the client
- // Also convert password to md5
- Client.Instance.Login(username, Encryption.Md5Sum(password));
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