0421 UI Stage

2021. 4. 21. 12:33unity

 

 

 

스테이지 상태에 따라 이미지 활성화 시키기

using UnityEngine;

public class UIStage : MonoBehaviour
{
    public UIStageItem[] arrUIStageitems;
    // Start is called before the first frame update
    void Start()
    {
        for (int i = 0; i < this.arrUIStageitems.Length; i++) 
        {
            var uiStageItem = this.arrUIStageitems[i];
            uiStageItem.txtStageNum.text = (i + 1).ToString();
            if (i <5)
            {
                uiStageItem.Init(UIStageItem.eStageItemType.DOING);
            }
            else 
            {
                uiStageItem.Init(UIStageItem.eStageItemType.LOCK);
            }
        }
    }
using UnityEngine;
using UnityEngine.UI;

public class UIStageItem : MonoBehaviour
{
    public enum eStageItemType {
        COMPLETE, DOING, LOCK
    }
    public GameObject completeGo;
    public GameObject[] stars;
    public GameObject doing;
    public GameObject locked;
    public Text txtStageNum;
    private eStageItemType type;

    public void Init(eStageItemType type) 
    {
        this.type = type;
        switch (this.type) 
        {
            case eStageItemType.COMPLETE:
                {
                    completeGo.SetActive(true);
                    doing.SetActive(false);
                    locked.SetActive(false);
                }
                break;

            case eStageItemType.DOING:
                {
                    completeGo.SetActive(false);
                    doing.SetActive(true);
                    locked.SetActive(false);
                }
                break;

            case eStageItemType.LOCK:
                {
                    completeGo.SetActive(false);
                    doing.SetActive(false);
                    locked.SetActive(true);
                }
                break;
        }
    }
}

 

 

using UnityEngine;
using UnityEngine.UI;

public class UIStage : MonoBehaviour
{
    public UIStageItem[] arrUIStageItems;
    private int maxStage = 72;
    private int currentPage = 1;
    private int totalPage;
    public Button btnPrev;
    public Button btnNext;
    private NaviScroll naviScroll;
    // Start is called before the first frame update
    void Start()
    {
        this.totalPage = this.maxStage / this.arrUIStageItems.Length;
        this.btnPrev.onClick.AddListener(() => {
            this.PrevPage();
        });

        this.btnNext.onClick.AddListener(() => {
            this.NextPage();
        });

        if (this.currentPage == 1)
        {
            this.btnPrev.gameObject.SetActive(false);
        }
        else
        {
            this.btnPrev.gameObject.SetActive(true);
        }
        this.btnNext.gameObject.SetActive(true);

        for (int i = 0; i < this.arrUIStageItems.Length; i++)
        {
            var uiStageItem = this.arrUIStageItems[i];
            uiStageItem.txtStageNum.text = (i + 1).ToString();
            if (i <26)
            {
                uiStageItem.Init(UIStageItem.eStageItemType.DOING);
            }
            else {
                uiStageItem.Init(UIStageItem.eStageItemType.LOCK);
            }
        }
    }

    private void PrevPage()
    {
        if (this.currentPage == 1)
        {
            return;
        }
        this.currentPage--;

        Debug.LogFormat("currentPage: {0}, totalPage: {1}", this.currentPage, this.totalPage);

        var startIndex = (this.currentPage - 1) * this.arrUIStageItems.Length;
        var endIndex = startIndex + this.arrUIStageItems.Length;

        for (int i = 0; i < this.arrUIStageItems.Length; i++)
        {
            var uiStageItem = this.arrUIStageItems[i];
            uiStageItem.txtStageNum.text = (startIndex + i + 1).ToString();
        }
        if (this.currentPage == 1)
        {
            this.btnPrev.gameObject.SetActive(false);
        }
        else
        {
            this.btnPrev.gameObject.SetActive(true);
        }
        this.btnNext.gameObject.SetActive(true);

    }
    private void NextPage()
    {
        if (this.currentPage == this.totalPage)
        {
            return;
        }
        this.currentPage++;

        Debug.LogFormat("currentPage: {0}, totalPage: {1}", this.currentPage, this.totalPage);

        var startIndex = (this.currentPage - 1) * this.arrUIStageItems.Length;
        var endIndex = startIndex + this.arrUIStageItems.Length;

        for (int i = 0; i < this.arrUIStageItems.Length; i++)
        {
            var uiStageItem = this.arrUIStageItems[i];
            uiStageItem.txtStageNum.text = (startIndex + i + 1).ToString();
        }

        if (this.currentPage == this.totalPage)
        {
            this.btnNext.gameObject.SetActive(false);
        }
        else
        {
            this.btnNext.gameObject.SetActive(true);
        }
        this.btnPrev.gameObject.SetActive(true);
    }
}

 

'unity' 카테고리의 다른 글

0423 ui scroll view+데이터 테이블 연동  (0) 2021.04.23
0421 데이터 저장 및 로딩  (0) 2021.04.21
0420 Item Pick up+인벤토리 연동  (0) 2021.04.20
0420 UI Inventory  (0) 2021.04.20
0419 UI  (0) 2021.04.19