유니티 심화

LearnUGUI - Practice04 [Stage]

다모아 2023. 9. 6. 11:31

 

UIPageNext

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

public class UIPrevNext : MonoBehaviour
{
    [SerializeField]
    private Button btnPrev;
    [SerializeField]
    private Button btnNext;

    private int totalStageNum = 40; // 총 스테이지
    private int currentPageNum = 1; // 현재 페이지
    private int maxStageNum = 18; // 한 페이지의 마지막 스테이지
    private int endPageNum;
    // Start is called before the first frame update
    void Start()
    {
        this.Display();
        this.btnPrev.onClick.AddListener(() => {
            if(this.currentPageNum == 1)
            {
                Debug.Log("이전페이지로 갈 수 없습니다.");
            }
            else
            {
                Debug.Log("이전페이지로 가기");
                this.currentPageNum -= 1;
                this.Display();
            }
        });

        this.btnNext.onClick.AddListener(() => {
            if (this.currentPageNum == this.endPageNum)
            {
                Debug.Log("다음페이지로 갈 수 없습니다.");
            }
            else
            {
                Debug.Log("다음페이지로 가기");
                this.currentPageNum += 1;
                this.Display();
            }
        });
    }

    private void Display()
    {
        this.endPageNum = Mathf.CeilToInt((float)this.totalStageNum / this.maxStageNum);
        Debug.LogFormat("총 스테이지 : {0}", this.totalStageNum);
        Debug.LogFormat("현재 페이지 : {0}", this.currentPageNum);
        Debug.LogFormat("최대 페이지 : {0}", this.endPageNum);
        int endStageNum = this.currentPageNum * this.maxStageNum;
        int startStageNum = endStageNum - 17;
        //마지막 페이지
        if(this.currentPageNum == this.endPageNum)
        {
            endStageNum -= 14;
        }
        Debug.LogFormat("스테이지 : {0} ~ {1}", startStageNum, endStageNum);
    }
}

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

LearnUGUI - Test05 [Shop]  (0) 2023.09.07
LearnUGUI - Test04[Stage]  (0) 2023.09.06
fbx 파일 애니메이션  (0) 2023.09.05
LearnUGUI - Test02 [UIPopupName]  (0) 2023.09.05
LearnUGUI  (0) 2023.09.04