C#/수업내용

2020.05.22. 수업내용 - 로그인 (InputField 이용)

dev_sr 2020. 5. 24. 19:47

InputField에 텍스트를 제대로 표현하려면

Update에서 Text에 값을 할당해야한다.

 

InputField 컴포넌트에서

Caret Width 를 큰값으로 (최대 5) 움직이면 깜빡이는 커서가 넓어진다

Custom Caret Color 를 체크하면 원하는 커서 색으로 바꿀 수 있다. 

 

1. Login -로그인씬을 관리

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Login : MonoBehaviour
{
    public UILogin uiLogin;
    public UIPopUpLogin uiPopupLogin;
 
    void Start()
    {
        Debug.Log("1.Login::Start");
        this.Init();   
    }
 
    public void Init()
    {
        Debug.Log("2.Login::Init");
 
        this.uiLogin.Init();
        this.uiPopupLogin.Init();
 
        this.uiLogin.OnClickLoginBtn = () =>
        {
            Debug.Log("Login::uiLogin.OnClickLoginBtn 델리게이트 실행");
            this.uiPopupLogin.Show();
        };
 
        this.uiPopupLogin.closeBtn.onClick.AddListener(() =>
        {
            Debug.Log("uiPopupLogin::closeBtn: 닫기 버튼 누르기");
            this.uiPopupLogin.Hide();
        });
 
    }
    
}
 

 

2. UILogin - 로그인 씬 안에 UI요소들 관리

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class UILogin : MonoBehaviour
{
    public Button btn;
    public System.Action OnClickLoginBtn;
 
    public void Init()
    {
        Debug.Log("3.UILogin::Init");
 
        this.btn.onClick.AddListener(() =>
        {
            Debug.Log("UILogin::btn: 로그인 버튼 누르기");
            Debug.Log("UILogin::OnClickLoginBtn: 델리게이트 호출");
 
            this.OnClickLoginBtn();
 
           
        });
        
    }
}
 

 

3. UIPopUpLogin - 로그인 팝업창 관리

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Collections;
using System.Collections.Generic;
using System.Runtime.ExceptionServices;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Video;
 
public class UIPopUpLogin : MonoBehaviour
{
    public Button closeBtn;
    public Button signUpBtn;
    public Button forgetPWBtn;
    public Button loginBtn;
    public Button rememberOnBtn;
    public Button rememberOffBtn;
 
    public InputField emailInputField;
    public InputField pwInputField;
 
    private string emailTxt;
    private string pwTxt;
    private bool isRememberUser;
 
    private void Awake()
    {
        //DontDestroyOnLoad(this);
    }
 
    public void Init()
    {
        Debug.Log("4.UIPopUpLogin::Init");
 
        this.isRememberUser = true;
 
        this.signUpBtn.onClick.AddListener(() =>
        {
            Debug.Log("UIPopUpLogin::signUp 버튼 클릭");
            Debug.Log("회원가입 하기");
        });
 
        this.forgetPWBtn.onClick.AddListener(() =>
        {
            Debug.Log("UIPopUpLogin::forgetPWBtn 버튼 클릭");
            Debug.Log("패스워드 찾아주기");
        });
 
        this.rememberOnBtn.onClick.AddListener(() =>
        {
            Debug.Log("UIPopUpLogin::rememberOnBtn 버튼 클릭");
            Debug.Log("사용자 기억안하기");
            this.rememberOffBtn.gameObject.SetActive(true);
            this.rememberOnBtn.gameObject.SetActive(false);
            this.isRememberUser = false;
        });
 
        this.rememberOffBtn.onClick.AddListener(() =>
        {
            Debug.Log("UIPopUpLogin::rememberOffBtn 버튼 클릭");
            Debug.Log("사용자 기억하기");
            this.rememberOnBtn.gameObject.SetActive(true);
            this.rememberOffBtn.gameObject.SetActive(false);
            this.isRememberUser = true;
        });
 
 
 
        //사용자의 아이디, 비밀번호, 기억할 건지 여부 저장
        this.loginBtn.onClick.AddListener(() =>
        {
            Debug.Log("UIPopUpLogin::loginBtn 버튼 클릭");
            Debug.Log("로그인하기");
 
            if (this.emailTxt != null)
            {
                Debug.LogFormat("이메일 아이디: {0}",this.emailTxt);
            }
            if(this.pwTxt != null)
            {
                Debug.LogFormat("패스워드: {0}",this.pwTxt);
            }
 
            Debug.LogFormat("유저 기억 여부{0}",this.isRememberUser);
 
 
            //로비씬으로 넘김
            var asyncOper = SceneManager.LoadSceneAsync("Lobby");
            asyncOper.completed += (obj) =>
             {
                 var Lobby = GameObject.FindObjectOfType<Lobby>();
                 Lobby.Init(this.emailTxt, this.pwTxt, this.isRememberUser);
                 //Object.Destroy(this.gameObject);
 
             };
 
        });
 
    }
 
    public void Show()
    {
        Debug.Log("UIPopUpLogin::Show");
        this.gameObject.SetActive(true);
    }
 
    public void Hide()
    {
        Debug.Log("UIPopUpLogin::Hide");
        this.gameObject.SetActive(false);
    }
 
    private void Update()
    {
        this.emailTxt = this.emailInputField.text;
        this.pwTxt = this.pwInputField.text;
    }
}