using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting.Antlr3.Runtime.Tree;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;
public class TestChestMain : MonoBehaviour
{
//버튼5개
[SerializeField] private Button[] buttons;
//텍스처 5개
[SerializeField] SpriteAtlas spriteAtlas;
private string prefix = "shop_img_chest_close_m_0";
[SerializeField] private UIShopCellView uIShopCellView;
enum ChestName
{
Wooden, Silver, Golden, Epic, Legendary
}
ChestName chestName;
void Start()
{
for(int i=0; i<buttons.Length; i++)
{
string spriteName = string.Format("{0}{1}", prefix, i);
this.spriteAtlas.GetSprite(spriteName);
int idx = i;
buttons[idx].onClick.AddListener(() =>
{
uIShopCellView.chestImage.sprite = this.spriteAtlas.GetSprite(spriteName);
uIShopCellView.text.text = Enum.GetName(typeof(ChestName), idx) + " Chest";
});
}
}
}
2. TestChestMain.cs
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UIShopCellView : MonoBehaviour
{
public Texture2D img0;
public Image chestImage;
public TMP_Text text;
private void Start()
{
Sprite sprite = Sprite.Create(img0, new Rect(0, 0, img0.width, img0.height), new Vector2(0.5f, 0.5f));
Debug.LogFormat("sprite: {0}", sprite);
chestImage.sprite = sprite;
chestImage.SetNativeSize();
chestImage.GetComponent<RectTransform>().sizeDelta = new Vector2(307, 281);
}
}
3. UIShopCellView.cs
'산대특 > 게임 UIUX프로그래밍' 카테고리의 다른 글
[LearnUGUI] Settings 화면 만들기 (0) | 2024.02.10 |
---|---|
[LearnUGUI] ShopChest 동적 스크롤 뷰 + 데이터 연동 구현 (0) | 2024.02.08 |
[LearnUGUI] 스킬 버튼 만들기 (+쿨타임) (0) | 2024.02.08 |
[LeanUGUI] TabMenu에 DOTween으로 애니메이션 적용하기 (0) | 2024.02.08 |
[LearnGUI] 이름 설정 및 변경과 화면 클릭 시 경험치 획득과 레벨 업 구현 (0) | 2024.02.07 |