1. 오류 상황

데이터 연동 및 셀 생성은 되지만, 오류로 인해 씬이 작동을 하지 않는다.

 

계속 찾다 보니 

 

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 스크립트 상황

3. 이 부분에서 에러가 나는 것 같다.
3. 위 부분을 임의로 주석처리 후, 테스트를 해보았다.
4.  씬이 잘 실행이 되는 모습

 

하지만 위 코드를 주석 처리 함으로써 버튼 클릭 이벤트가 작동되지 않는다.

 

왜 그런 오류(NullReferenceException)가 나는지 계속 찾아봐야 겠다.

반응형

+ Recent posts