본문 바로가기

유니티/수업 내용

[UGUI] UI만들기 - Tab

 

 

 

더보기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;

public class TestTab : MonoBehaviour
{
    public GameObject focusGo;
    public UnityAction OnClick;

    void Start()
    {
        this.GetComponent<Button>().onClick.AddListener(() =>
        {
            Debug.Log("click");
            this.OnClick();
        });
    }

    public void FocusOn()
    {
        this.focusGo.SetActive(true);
    }

    public void FocusOff()
    {
        this.focusGo.SetActive(false);
    }
}
더보기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestTabs : MonoBehaviour
{
    public TestTab[] tabs;

    void Start()
    {
        this.AllOff();
        foreach (var tab in this.tabs)
        {
            tab.OnClick = () =>
            {
                this.SelectTab(tab);
            };
        }
    }

    void AllOff()
    {
        foreach (var tab in this.tabs)
        {
            tab.FocusOff();
        }
    }

    void SelectTab(TestTab tab)
    {
        this.AllOff();
        tab.FocusOn();
    }
}

'유니티 > 수업 내용' 카테고리의 다른 글

[UGUI] 버젯, InputField  (0) 2022.01.18
[UGUI] 스킬버튼, 아이템버튼  (0) 2022.01.18
[UGUI] UI 만들기  (0) 2022.01.18
씬전환하기  (0) 2022.01.18
[3D MiniRPG] 플레이어 스탯, 레벨업, UI  (0) 2022.01.18