Unity2D

Unity) [UGUI] 동적스크롤뷰를 사용하여 스테이지 정보 표시

HSH12345 2023. 4. 4. 01:09
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIPopupCoinDetail : MonoBehaviour
{
    public Button[] btnCloses;
    public GameObject[] CoinDetails;
    //임시값
    private List<System.Tuple<int, int>> depositList;

    void Start()
    {

        this.depositList = new List<System.Tuple<int, int>>();
        this.depositList.Add(new System.Tuple<int, int>(100, 200));
        this.depositList.Add(new System.Tuple<int, int>(200, 300));
        this.depositList.Add(new System.Tuple<int, int>(300, 400));
        this.depositList.Add(new System.Tuple<int, int>(350, 500));
        this.depositList.Add(new System.Tuple<int, int>(600, 700));
        this.depositList.Add(new System.Tuple<int, int>(400, 800));
        this.depositList.Add(new System.Tuple<int, int>(800, 900));
        this.depositList.Add(new System.Tuple<int, int>(1000, 1000));
        this.depositList.Add(new System.Tuple<int, int>(300, 500));
        this.depositList.Add(new System.Tuple<int, int>(10, 100));

        for (int i = 0; i < this.btnCloses.Length; i++)
        {
            int idx = i;

            this.btnCloses[idx].onClick.AddListener(() =>
            {
                this.gameObject.SetActive(false);
            });
        }


        for(int i = 0; i < this.depositList.Count; i++)
        {
            this.CoinDetails[i].SetActive(true);
            this.CoinDetails[i].transform.Find("txtCoinDetail").GetComponent<Text>().text = 
                string.Format("{0}스테이지 : {1}/{2} 획득", i + 1, this.depositList[i].Item1, this.depositList[i].Item2);
        }
    }
}