
데이터 연동 및 셀 생성은 되지만, 오류로 인해 씬이 작동을 하지 않는다.
계속 찾다 보니
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UIGoldCell : MonoBehaviour
{
public enum eGoldType
{
Tiny,
Fistful,
Pouch,
Box,
Chest,
Vault
}
[SerializeField]
protected Button btnPrice;
[SerializeField]
protected eGoldType goldType;
[SerializeField]
protected int value;
[SerializeField]
protected float price;
[SerializeField]
private TMP_Text txtName;
[SerializeField]
private Image icon;
[SerializeField]
private TMP_Text txtValue;
[SerializeField]
private TMP_Text txtPrice;
public eGoldType GoldType
{
get
{
return goldType;
}
}
public int Value => value;
public float Price => price;
//public int Price -> 동일한 기능을 하는 코드
//{
// get { return this.price; }
//}
public System.Action onClickPrices;
public virtual void Init(GoldData data)
{
Debug.LogFormat("[UIGoldCell] Init : {0}", this.GoldType);
price = data.price;
value = data.value;
txtName.text = data.name;
txtPrice.text = "US $" + price.ToString();
txtValue.text = value.ToString() + "Gold";
goldType = (eGoldType)data.type;
var atlas = AtlasManager.instance.GetAtlas("UIAtlasGold");
icon.sprite = atlas.GetSprite(data.sprite_name);
icon.SetNativeSize();
btnPrice.onClick.AddListener(() =>
{
Debug.LogFormat("{0}, {1}", this.goldType, this.price);
onClickPrices();
});
}
}
2. UIGoldCell 스크립트 상황



하지만 위 코드를 주석 처리 함으로써 버튼 클릭 이벤트가 작동되지 않는다.
왜 그런 오류(NullReferenceException)가 나는지 계속 찾아봐야 겠다.
반응형
'KDT > 유니티 심화' 카테고리의 다른 글
LearnUGUI (Gold Packs - 데이터 테이블 만들고 연동하기) - 3 (完) (0) | 2023.09.13 |
---|---|
LearnUGUI (Gold Packs - 데이터 테이블 만들고 연동하기) - 2 (0) | 2023.09.12 |
LearnUGUI연습 (8. ShopChest 데이터 연동 하기) (0) | 2023.09.10 |
LearnUGUI 연습 (7. ShopChest 정적 스크롤뷰 관리 하는 스크립트 만들기) (0) | 2023.09.10 |
LearnUGUI 연습 (6. ShopChest 정적 스크롤뷰 만들기) (0) | 2023.09.09 |