본문 바로가기
공허의 유산/사상의 도구

Unity3d Input field의 Password 문자열 얻기

by 바른생활머시마 2023. 4. 12.
728x90
반응형

공부 겸 Unity3d로 작은 케쥴얼 게임을 만들어 보려고, 사용자 가입 화면부터 만들어 봤습니다.

이게 또 막상 직접 해보려니까 작은 것들부터 걸리는게 참 많네요.

이래서 백문이 불여일타!

 

계정 정보를 입력하는 UI를 대충 만들고, 입력 된 문자열을 얻어와 로그로 출력하는 것 부터 해보았습니다.

 

사용자 계정은 Input field 하위의 Text 오브젝트를 가져와서 그 text property를 조회하니 잘 되었는데,

 암호를 입력 받는 Input field의 타입을 암호 노출 방지를 위해 Password로 하면, 그 하위 Text 오브젝트의 text property를 조회하니 **** 별 표시만 나옵니다. 즉, 화면에 보이는 그 문자열 그대로 얻어졌습니다.

꽤 여러가지 조사를 하고 시도를 해 봤는데, 해결 방법은 허무하게도, Inputfield의 text property를 가져오면 되는 것이었습니다. Text의 text property가 아니고~!!

 

아래 코드에서 CustomSignup이 로그인을 누르면 호출되는 함수입니다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

// 뒤끝 SDK namespace 추가
using BackEnd;

public class BackendManager : MonoBehaviour {

    public GameObject txtID;
    public GameObject inputPWD;

    // Start is called before the first frame update
    void Start()
    {
            var bro = Backend.Initialize(true);
            if (bro.IsSuccess())
            {
                // 초기화 성공 시 로직
                Debug.Log("초기화 성공: " + bro.ToString() );
                //CustomSignUp();
            }
            else
            {
                // 초기화 실패 시 로직
                Debug.LogError("초기화 실패: " +  bro.ToString());
            }
    }

    // Update is called once per frame
    void Update() {
        // 뒤끝 비동기 함수 사용 시, 메인쓰레드에서 콜백을 처리해주는 Dispatch
        Backend.AsyncPoll();
    }

    //초기화 성공 이후 버튼 등을 통해 함수 실행
    public void CustomSignUp()
    {
        Text idText = txtID.GetComponent<Text>();
        InputField pwdInput = inputPWD.GetComponent<InputField>();

        string id = idText.text;
        string password = pwdInput.text;

        Debug.Log(id+"  "+password);
    }   
    

    
}

각 오브젝트는 public으로 연결을 해두었습니다.

오묘한 세계~~~

세상은 참 배울 것이 많네요. 놀 것도 많고.

728x90
반응형

댓글