유니티 심화

LearnUGUI - Test02 [UIPopupName]

다모아 2023. 9. 5. 12:07

Test02PopupName

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

public class Test02UIPopupName : MonoBehaviour
{
    [SerializeField]
    private Test02Button button;
    [SerializeField]
    private Test02InputField input;
    // Start is called before the first frame update
    void Start()
    {
        for(int i = 0; i < this.button.arrOnOff.Length; i++)
        {
            int idx = i;
            this.button.arrOnOff[idx].onClick.AddListener(() => {
                if(this.input.str != null)
                {
                    Debug.Log(this.input.str);
                }
                else
                {
                    Debug.Log("닉네임을 입력하세요");
                }
            });
        }
    }

    private void Update()
    {
        if (this.input.str != null)
        {
            this.button.On();
        }
        else
        {
            this.button.Off();
        }
    }
}

 

Test02Main

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

public class Test02Main : MonoBehaviour
{
    [SerializeField]
    private Test02UIPopupName uiPopupName;

    [SerializeField]
    private Button btn; //게임로드버튼
    // Start is called before the first frame update
    void Start()
    {
        this.btn.onClick.AddListener(() => {
            this.uiPopupName.gameObject.SetActive(true);
            this.btn.gameObject.SetActive(false);
        });
    }
}

 

Test02InputField

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class Test02InputField : MonoBehaviour
{
    [SerializeField]
    private TMP_InputField input;

    public string str = null;

    private void Update()
    {
        if (this.input.text == "")
        {
            this.str = null;
        }
        else
        {
            this.str = this.input.text;
        }
    }
}

 

Test02Button

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

public class Test02Button : MonoBehaviour
{
    private enum eButtonType
    {
        On, Off
    }

    public Button[] arrOnOff;

    public void On()
    {
        this.arrOnOff[(int)eButtonType.On].gameObject.SetActive(true);
        this.arrOnOff[(int)eButtonType.Off].gameObject.SetActive(false);
    }

    public void Off()
    {
        this.arrOnOff[(int)eButtonType.Off].gameObject.SetActive(true);
        this.arrOnOff[(int)eButtonType.On].gameObject.SetActive(false);
    }
}

UIPopupName 프리팹화

Test02Main

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

public class Test02Main : MonoBehaviour
{
    [SerializeField]
    private Test02UIPopupName uiPopupName;

    [SerializeField]
    private Button btn; //게임로드버튼
    // Start is called before the first frame update
    void Start()
    {
        this.btn.onClick.AddListener(() => {
            Instantiate(this.uiPopupName).gameObject.SetActive(true);
            this.btn.gameObject.SetActive(false);
        });
    }
}

'유니티 심화' 카테고리의 다른 글

LearnUGUI - Practice04 [Stage]  (0) 2023.09.06
fbx 파일 애니메이션  (0) 2023.09.05
LearnUGUI  (0) 2023.09.04
SaveAndLoad - UISlot  (0) 2023.09.01
SaveAndLoad - 캐릭터 프리팹 인스턴스화하기  (0) 2023.09.01