1. gem_data.xlsx

 

2. gem_data.json
3. 실행 이미지(Game)

 

4. 실행 이미지 (All)

 

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;

public class UIGemScrollView : MonoBehaviour
{
    [SerializeField] private GemCell[] gemCells;
    [SerializeField] private GameObject GemCellPrefab;
    [SerializeField] private GameObject contents;
    [SerializeField] private SpriteAtlas gemAtlas;

    void Start()
    {
        gemCells = new GemCell[ShopDataManager.Instance.dicGemDatas.Count];

        for (int i = 0; i < ShopDataManager.Instance.dicGemDatas.Count; i++)
        {
            GameObject gemCellGO = Instantiate(GemCellPrefab, contents.transform);
            gemCells[i] = gemCellGO.GetComponent<GemCell>();

        }



        int idx = 100;

        for (int i = 0; i < gemCells.Length; i++)
        {

            gemCells[i].gemTitle.text = ShopDataManager.Instance.dicGemDatas[idx].gemName;
            gemCells[i].gemImage.sprite = gemAtlas.GetSprite(ShopDataManager.Instance.dicGemDatas[idx].imageName);
            gemCells[i].gemImage.SetNativeSize();
            gemCells[i].gemImage.rectTransform.anchoredPosition = new Vector2(ShopDataManager.Instance.dicGemDatas[idx].posX, ShopDataManager.Instance.dicGemDatas[idx].posY);
            gemCells[i].gemValue.text = Convert.ToString(ShopDataManager.Instance.dicGemDatas[idx].value);
            gemCells[i].gemPrice.text = "US $" + Convert.ToString(ShopDataManager.Instance.dicGemDatas[idx].price);
            gemCells[i].gemParticles[i].gameObject.SetActive(true);
            for(int j = 0; j< gemCells.Length; j++)
            {
                gemCells[i].gemParticles[j].gameObject.SetActive(false);
            }
            gemCells[i].gemParticles[i].gameObject.SetActive(true);

            if (gemCells[i].gemTitle.text == "Tiny of Gem")
            {
                gemCells[i].topGlows[0].gameObject.SetActive(true); //topGlows[0] : Red
                gemCells[i].flames[1].gameObject.SetActive(true); //frames[1] : Red
                gemCells[i].labels[1].gameObject.SetActive(true); //labels[1] : Red
            }
            else if (gemCells[i].gemTitle.text == "Pouch of Gem")
            {
                gemCells[i].topGlows[1].gameObject.SetActive(true); //topGlows[1] : Blue
                gemCells[i].flames[2].gameObject.SetActive(true); //frames[2] : Blue
                gemCells[i].labels[0].gameObject.SetActive(true); //labels[0] : Blue



            }
            else
            {
                gemCells[i].flames[0].gameObject.SetActive(true); //frames[0] : Normal

            }



            idx++;

        }
    }

}

5. UIGemScrollView.cs

 

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShopDataManager
{
    public static readonly ShopDataManager Instance = new ShopDataManager();
    public Dictionary<int, GemData> dicGemDatas = new Dictionary<int, GemData>();

    private ShopDataManager() { }

    public void LoadGemData()
    {
        var asset = Resources.Load<TextAsset>("Gem_data");
        var json = asset.text;

        var gemDatas = JsonConvert.DeserializeObject<GemData[]>(json);


        foreach (var gemData in gemDatas)
        {
            this.dicGemDatas.Add(gemData.id, gemData);
        }
        Debug.LogFormat("gem_data Load Complete! => Count : {0}", this.dicGemDatas.Count);


    }
}

6. ShopDataManager.cs

 

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

public class GemData : MonoBehaviour
{
    public int id;
    public string gemName;
    public string imageName;
    public int value;
    public float price;
    public float posX;
    public float posY; 
}

7. GemData.cs

 

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

public class GemCell : MonoBehaviour
{
    public Image[] topGlows; //0: Red , 1: Blue
    public Image[] flames; //0: Normal, 1: Red, 2: Blue
    public Image[] labels; //0: Blue, 1: Red
    public Image gemImage;
    public GameObject[] gemParticles; // 0 ~ 5  
    public TMP_Text gemTitle;
    public TMP_Text gemValue;
    public TMP_Text gemPrice;

}

8. GemCell.cs

 

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

public class UIShopMain : MonoBehaviour
{
    [SerializeField] private UIGemScrollView gemScrollView;


    private void Awake()
    {
        ShopDataManager.Instance.LoadGemData();

    }
}

 9. UIShopMain.cs

+ Recent posts