UNITY/PROJECT

[๊ตฌํ˜„] ์œ ๋‹ˆํ‹ฐ๋กœ ์‰ฝ๊ฒŒ ์ƒ์  ๊ตฌํ˜„ํ•˜๊ธฐ

ozllzL 2021. 12. 8. 18:39

https://dowlsovo.tistory.com/84

 

[๊ตฌํ˜„] ์‰ฝ๊ฒŒ ์ธ๋ฒคํ† ๋ฆฌ ๊ตฌํ˜„ํ•˜๊ธฐ 1

์ธ๋ฒคํ† ๋ฆฌ์— ๋„ฃ์–ด์•ผ ํ•˜๋Š” ์•„์ดํ…œ ๊ฐœ์ˆ˜๊ฐ€ ์•„์ฃผ ๋งŽ์ง€๋Š” ์•Š์„ ๊ฒฝ์šฐ ์ข‹์€ ๋ฐฉ๋ฒ•์ธ ๊ฒƒ ๊ฐ™๋‹ค. 1. ์•„์ดํ…œ ์ •๋ณด json์ €์žฅ ์˜์–ดํŒ์„ ๊ฒจ๋ƒฅํ•˜์—ฌ ์ด๋ ‡๊ฒŒ ์ผ๋Š”๋ฐ ๊ผญ ์ด๋ ‡๊ฒŒ ์•ˆํ•ด๋„ ๋œ๋‹ค [   {     "Item": [     

dowlsovo.tistory.com

https://dowlsovo.tistory.com/85

 

[๊ตฌํ˜„] ์‰ฝ๊ฒŒ ์ธ๋ฒคํ† ๋ฆฌ ๊ตฌํ˜„ํ•˜๊ธฐ 2

1. ์ธ๋ฒคํ† ๋ฆฌ ์ƒ๋‹จ ์นดํ…Œ๊ณ ๋ฆฌ ์Šค์œ„์น˜ ๊ฐ ๋ฒ„ํŠผ์—๋Š” SetIndex๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ๋„ฃ์–ด ์ค€๋‹ค. ๋ˆ„๋ฅธ ๋ฒ„ํŠผ์ด ๋ช‡ ๋ฒˆ์ธ์ง€๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›์•„ ํ•ด๋‹น ์ˆ˜์— ๋งž๋Š” ์นดํ…Œ๊ณ ๋ฆฌ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค. public class SelectIndex : MonoBehaviour { pu

dowlsovo.tistory.com

์–˜๋„ค๋ฅผ ๋ณด๊ณ  ์™€์•ผ ์ดํ•ด๊ฐ€ ๋  ๊ฒƒ์ด๋‹ค!

์ƒ์ ๊ณผ ์ธ๋ฒคํ† ๋ฆฌ๋Š” ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์ด ๊ฝค ์žˆ์–ด ๋นผ๋Š” ๋ถ€๋ถ„์ด ๋งŽ์„ ๊ฒƒ์ด๋‹ค.

 

1. ์ƒ์ ์— ์•„์ดํ…œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

์—ญ์‹œ ๋ชจ๋“  ์•„์ดํ…œ๋“ค์„ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด์ค€๋‹ค.

๋Œ€์‹ ์— ์ด๋ฒˆ์—” Item์— count๋Š” ์—†๋‹ค. ํ•„์š”๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ

๊ทธ๋ฆฌ๊ณ  ScrollView์“ฐ๋Š” ๊ฒƒ ๊นŒ์ง€ ๋˜‘๊ฐ™๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  LoadStore์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋งŒ๋“ ๋‹ค.

public class LoadStoreItems : LoadItems
{
    ...

    //์Šคํ† ์–ด ์•„์ดํ…œ ๋กœ๋“œ
    public override void Refresh()
    {
        goods = GameObject.FindGameObjectsWithTag(selectIndex.index.ToString());
        itemCount = GetComponent<ItemSaveLoad>().GetItemCount();

        int selectIndexNum = (int)selectIndex.index;

        if (selectIndexNum == ((int)InventoryIndex.Item))
        {
            for (int i = 0; i < goods.Length; i++)
            {
                goods[i].transform.SetParent(inventorySlotBox.transform);
            }
        }
        else
        {
            for (int i = 0; i < goods.Length; i++)
            {
                int id = goods[i].GetComponent<ItemInfo>().id - 1;
                if (!itemCount.have[selectIndexNum -1].haveList[id])
                {
                    goods[i].transform.SetParent(inventorySlotBox.transform);
                }

            }
        }
        ExpandInventory();
    }

  ...
}

์•„์ดํ…œ์€ ๋ฌด์กฐ๊ฑด ๋‹ค ์Šฌ๋กฏ์œผ๋กœ ๋“ค์–ด๊ฐ€๊ณ ,

ํ—ค์–ด, ์˜์ƒ์€ ๊ตฌ๋งคํ•˜์ง€ ์•Š์€ ๊ฒƒ๋งŒ ๋“ค์–ด๊ฐ„๋‹ค.

 

2. ๊ตฌ๋งค ์ฐฝ ๋งŒ๋“ค๊ธฐ

์†”์งํžˆ ์ด๊ฑด ๋…ธ๊ฐ€๋‹ค๋‹ค. ๊ทธ๋ž˜์„œ ์ฝ”๋“œ๋Š” ์ƒ๋žตํ•˜๊ฒ ๋‹ค.

๊ทธ๋ƒฅ ์ €๋ฒˆ ์•„์ดํ…œ ์ •๋ณด json์—์„œ ์ •๋ณด ์–ป์–ด์™€์„œ ํด๋ฆด ๋•Œ๋งˆ๋‹ค ์„ธํŒ… ํ•ด์„œ setActiveํ•˜๋ฉด ๋œ๋‹ค.

 

3. ๊ตฌ๋งค ๊ตฌํ˜„

๋ญ”๊ฐ€ ๋ณต์žกํ•œ ๋ณด์•ˆ ๊ทธ๋Ÿฐ๊ฒŒ ๋“ค์–ด๊ฐ€์•ผ ํ•  ๊ฒƒ ๊ฐ™๊ธด ํ•œ๋ฐ...

๊ทธ๊ฒƒ๊นŒ์ง„ ๋‚˜๋„ ์ž˜ ๋ชจ๋ฅธ๋‹ค ํ—คํ—ท

์ผ๋‹จ ๊ทธ๋ƒฅ ๊ตฌํ˜„ํ–ˆ๋‹ค.

public class StoreSystem : MonoBehaviour
{
    public Slider itemCountToBuySlider;

    private ShowGoodsInfo showInfo;
    private ItemSaveLoad saveLoad;


    private int priceToPay;

    private void Start()
    {
        showInfo = GetComponent<ShowGoodsInfo>();
        saveLoad = GetComponent<ItemSaveLoad>();
    }

    public void Buy()
    {
        ItemCount itemCount = saveLoad.GetItemCount();

        int id = showInfo.GetID();
        int selectIndexNum = (int)GetComponent<SelectIndex>().index;
        if(priceToPay == 0)
            priceToPay = showInfo.GetPrice();

        //์•„์ดํ…œ ๊ฒฐ์ œ
        if (selectIndexNum == ((int)InventoryIndex.Item))
            itemCount.itemCounts[id] += ((int)itemCountToBuySlider.value);
        //์˜์ƒ, ํ—ค์–ด ๊ฒฐ์ œ
        else
            itemCount.have[selectIndexNum - 1].haveList[id] = true;

        PlayerInfo.AddCoin(-1 * priceToPay);
        saveLoad.SaveUpdate(itemCount);

        //์ดˆ๊ธฐํ™”
        itemCountToBuySlider.value = 1;
        showInfo.itemInfoPanel.SetActive(false);
    }

    //์•„์ดํ…œ ์Šฌ๋ผ์ด๋” ๊ฐœ์ˆ˜ ๊ฐ€์ ธ์˜ค๊ธฐ
    public void ValueChangeCheck()
    {
        priceToPay = showInfo.GetPrice() * ((int)itemCountToBuySlider.value);

        showInfo.SettingPriceFormula((int)itemCountToBuySlider.value, priceToPay);
    }
}

๊ฐœ์ˆ˜ ๋ฐ˜์˜ ํ•ด์„œ ์ €์žฅํ•˜๋Š” ์ฝ”๋“œ๋‹ค.

 

์ด๋ ‡๊ฒŒ ์Šคํ† ์–ด๊นŒ์ง€ ๋!